[R] re-arranging rows in data frame

R. Michael Weylandt michael.weylandt at gmail.com
Tue Mar 27 04:20:34 CEST 2012


library(reshape2)

x <- structure(list(ExpName = structure(c(1L, 1L, 1L, 1L, 2L, 2L,
2L, 3L, 3L), .Label = c("MM1-x1", "MM1-X2", "MMX-X3"), class = "factor"),
    Identifier = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 4L, 1L,
    2L), .Label = c("GSK", "GSK2", "GSK3", "GSK4"), class = "factor"),
    value = c(0.02, 0.001, 0.04, 0.1, 0.4, 0.1, 0.002, 0.4, 0.23
    )), .Names = c("ExpName", "Identifier", "value"), class =
"data.frame", row.names = c(NA,
-9L))

dcast(x, ExpName ~ Identifier)

Michael

On Mon, Mar 26, 2012 at 4:20 PM, Srinivas Iyyer
<srini_iyyer_bio at yahoo.com> wrote:
> Hi:
> sorry for asking simple question (not simple for me though).
>
> I have a data frame something like this:
>
> ExpName Identifier value
> MM1-x1 GSK 0.02
> MM1-x1 GSK2 0.001
> MM1-x1 GSK3 0.04
> MM1-x1 GSK4 0.1
> MM1-X2 GSK 0.4
> MM1-X2 GSK2 0.1
> MM1-X2 GSK4 0.002
> MMX-X3 GSK 0.4
> MMX-X3 GSK2 0.23
>
>
>
> I am interested in getting a long table something like this:
>
>  GSK GSK2 GSK3 GSK4 GSK..(n)
> MM1-x1 0.02 0.001 0.04 0.1
> MM1-X2 0.4 0.1  0.002
> MM1-X3 0.4 0.23
> MM1-Xn
>
>
> I am re-arranging my fields into more clean data frame.
>
> How is it possible to do this?
>
> thanks
> Srini
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list