wolfram mathematica - Adding a new column which depends on other elements in the same row -


i have problem handling dataset in mathematica. basically, want create new column "newcolumn" depends on 2 other columns, "a" , "b". values in "a" can either x or y. if x, want write b^2 new column , otherwise sqrt(b).

thanks, appreciate help!

a small example be:

column "a": x,y,y,x column "b": 1,3,4,5

and new column should be: 1,sqrt(3),2,25

 (example = { { x, 1 } , {y, 3} , {y, 4} , {x, 5 } }) // matrixform 

enter image description here

 (switch[ #[[1]] , y  , sqrt[#[[2]]] , x , #[[2]]^2] & /@ example )//matrixform 

enter image description here


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -