0

I just started using Mathematica and I hope that someone can help me with a small piece of code:

  • I have a variable "X" in a dataset A.
  • I want to create a new variable called "logX" which is the log of the variable X and add it as a new column in dataset A using "append" in Mathematica if possible.

Thanks a lot for the help!

2 Answers2

0

Try

dataset[MapIndexed[Append[#1, "Column2" -> Log[[1, 1]]] &]]

Where column $1$ is your data and the new column is column $2$.

  • Thank you for your answer! Unfortunately it is not working. I tried to write this code which in my view should work but it is not. Maybe you can tell where it fails? dataA1 = dataA1[All, Append[#, "logclientrevenues" -->log[#clientrevenues] ]&] – Lasse Holm Oct 20 '17 at 20:48
0
ds = Dataset[{<|"x" -> 5|>, <|"x" -> 10|>}]
Append[#, "lx" -> Log[#x]] & /@ ds
Alan
  • 231
  • Thank you for your answer! Unfortunately it is not working. I tried to write this code which in my view should work but it is not. Maybe you can tell where it fails? dataA1 = dataA1[All, Append[#, "logclientrevenues" -->log[#clientrevenues] ]&] – Lasse Holm Oct 20 '17 at 20:46
  • @LasseHolm Please try it exactly as I showed you: Append[#, "logclientrevenues" -> Log[#clientrevenues]] & /@ dataA1. Note that Log cannot be spelled log. – Alan Oct 20 '17 at 21:07
  • I tried running your suggested code by writing the following: dataA1 = dataA1["clientrevenues" -> 5|>, <|"clientrevenues" -> 10|>}] Append[#, "logclientrevenues" -> Log[#clientrevenues]] & /@ dataA1 but it is still not working. Either way, thanks for your inputs! – Lasse Holm Oct 20 '17 at 21:16
  • @LasseHolm What you wrote has many errors. Copy and paste what I wrote. – Alan Oct 20 '17 at 23:38