Generate log of variable and append to existing dataset

46 Views Asked by At

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

There are 2 best solutions below

4
On BEST ANSWER
ds = Dataset[{<|"x" -> 5|>, <|"x" -> 10|>}]
Append[#, "lx" -> Log[#x]] & /@ ds
1
On

Try

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

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