r - Add variable to melt function -


here input, question below:

targets <- read.csv("mir155aicda.csv", row.names=1, sep="", header=t)           head(targets)                 t0h t0.25h t0.5h  t1h  t2h  t3h  t6h t12h t24h t48h c0h c0.25h c0.5h c1h  c2h aicda          785   1150   707  513 1265 3268 8294 8625 7387 4397 677    911   673 737 1782 mmu-mir-155-3p 622    548   558 1213 1195 1172 1115 1883 3257 1900 499    562   584 543  580  targets.m <- melt(targets) > head(targets.m)   variable     value 1      t0h  9.616549 2      t0h  9.280771 3   t0.25h 10.167418 4   t0.25h  9.098032 5    t0.5h  9.465566 6    t0.5h  9.124121 

question: how add aicda , mmu-mir-155-2p variable?

i want this:

      id                variable     value 1   aicda                  t0h    9.616549 2   mmu-mir-155-3p        t0h     9.280771 3   aicda                  t0.25h 10.167418 4   mmu-mir-155-3p          t0.25h  9.098032 5   aicda                  t0.5h   9.465566 6  mmu-mir-155-3p          t0.5h  9.124121 

you need put rownames in column , specify id variable melt:

df <- read.table(text="               t0h t0.25h t0.5h  t1h  t2h  t3h  t6h t12h t24h t48h c0h c0.25h c0.5h c1h  c2h aicda          785   1150   707  513 1265 3268 8294 8625 7387 4397 677    911   673 737 1782 mmu-mir-155-3p 622    548   558 1213 1195 1172 1115 1883 3257 1900 499    562   584 543  580",header=true)  df$id <- rownames(df) library(reshape2) melt(df,id="id") 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -