[R] Transpose of the rows

Blaser Nello nblaser at ispm.unibe.ch
Wed Jun 26 14:20:22 CEST 2013


reshape(dta, idvar="id", timevar="name", direction="wide")


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of Nico Met
Sent: Mittwoch, 26. Juni 2013 13:38
To: R help
Subject: [R] Transpose of the rows

Dear R users,

I am using a big data matrix and need to transpose rows (formatting of
input matrix). I would like write a general code for this example.

for example: my input file is "dta"

 dput(dta)
structure(list(id = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L), .Label = c("TN00016-003A", "TN00016-014A",
"TN00031-014A"), class = "factor"), name = structure(c(1L, 2L, 3L, 4L,
5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L), .Label = c("AreaCycl",
"AreaEmer", "AreaMax", "HeightMax", "nrfilledseed"), class = "factor"),
    value = structure(c(3L, 7L, 8L, 14L, 12L, 1L, 2L, 9L, 5L,
    13L, 11L, 10L, 4L, 6L), .Label = c("-0,584379415", "-0,842892819",
    "-1,399894415", "-1200,824457", "-13,59414667", "-25,86897333",
    "-3,277150907", "-3281,076515", "-7939,444248", "0,174160882",
    "0,800196212", "1,825", "12,2", "8,434493333"), class = "factor")),
...Names = c("id", "name", "value"), class = "data.frame", row.names =
c(NA, -14L
))

And output should look like this:

dput(dta1)
structure(list(id = structure(1:3, .Label = c("TN00016-003A",
"TN00016-014A", "TN00031-014A"), class = "factor"), AreaCycl =
structure(c( 2L, 1L, 3L), .Label = c("-0,584379415", "-1,399894415",
"0,800196212"
), class = "factor"), AreaEmer = structure(c(2L, 1L, 3L), .Label = c(
"-0,842892819", "-3,277150907", "0,174160882"), class = "factor"),
AreaMax = structure(c( 2L, 3L, 1L), .Label = c("-1200,824457",
"-3281,076515", "-7939,444248"
), class = "factor"), HeightMax = structure(c(3L, 1L, 2L), .Label = c(
"-13,59414667", "-25,86897333", "8,434493333"), class = "factor"),
nrfilledseed = structure( c(1L, 2L, NA), .Label = c("1,825", "12,2"),
class = "factor")), .Names = c("id", "AreaCycl", "AreaEmer", "AreaMax",
"HeightMax", "nrfilledseed"
), class = "data.frame", row.names = c(NA, -3L))

Thanks for your help.

Nico

	[[alternative HTML version deleted]]

______________________________________________
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