r - Transform data frame with column values as column names -


i have dataframe looks this:

               variable              name description value  smts gtex-n7ms-0007-sm-2d7w1 ensg00000223972.4     ddx11l1     0 blood gtex-n7ms-0007-sm-2d7w1 ensg00000227232.4      wash7p   158 blood gtex-n7ms-0008-sm-4e3ji ensg00000223972.4     ddx11l1     0  skin gtex-n7ms-0008-sm-4e3ji ensg00000227232.4      wash7p   166  skin gtex-n7ms-0011-r10a-sm-2hmjk ensg00000223972.4     ddx11l1     0 brain gtex-n7ms-0011-r10a-sm-2hmjk ensg00000227232.4      wash7p   209 brain 

i want transform such values in description column become column names, , values in value column become column values:

               variable   ddx11l1    wash7p    smts gtex-n7ms-0007-sm-2d7w1         0       158   blood gtex-n7ms-0008-sm-4e3ji         0       166    skin gtex-n7ms-0011-r10a-sm-2hmjk    0       209   brain 

i tried using cast (e.g. dcast(final, value~name) , other combinations too) don't want function (like mean, sum etc) apply transformation, returns me length of objects. want values is. suggestions appreciated.

this seems give results you're looking for:

library(reshape2) dcast(mydf, variable + smts ~ description, value.var="value") #                       variable  smts ddx11l1 wash7p # 1      gtex-n7ms-0007-sm-2d7w1 blood       0    158 # 2      gtex-n7ms-0008-sm-4e3ji  skin       0    166 # 3 gtex-n7ms-0011-r10a-sm-2hmjk brain       0    209 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -