Re: [R] how to transform a data file

2011-11-29 Thread Petr PIKAL
Hi option 3 library(reshape) melt(d, id.vars="id") Regards Petr > Hi PJ, > > Try > > # some data > id <- 1:20 > m <- matrix(sample(0:1, 200, TRUE), ncol = 10) > colnames(m) <- paste('V', 1:10, sep = "") > d <- data.frame(id, m) > d > > # option 1 > cbind(rep(d$id, each = ncol(d)-1), matrix(u

Re: [R] how to transform a data file

2011-11-28 Thread Jeff Newmiller
library(reshape2) # sample data because you didn't provide any dta <- as.data.frame( matrix( sample( 0:1, 100, replace=TRUE ), ncol=10 ) ) dta <- cbind( IDN=1:10, dta ) # The command you couldn't figure out meltdta <- melt( dta, "IDN" ) --

Re: [R] how to transform a data file

2011-11-28 Thread Jorge I Velez
Hi PJ, Try # some data id <- 1:20 m <- matrix(sample(0:1, 200, TRUE), ncol = 10) colnames(m) <- paste('V', 1:10, sep = "") d <- data.frame(id, m) d # option 1 cbind(rep(d$id, each = ncol(d)-1), matrix(unlist(t(d[,-1])), ncol = 1)) # option 2 cbind(rep(d$id, each = ncol(d) - 1), stack(d[,-1])[,-

[R] how to transform a data file

2011-11-28 Thread pat j
Hello R people, I have a data file with 101 numeric variables: one variable called IDN (the individual's unique id number, which I need to retain, and which ranges from 1000 to 1320; some numbers are obviously skipped), and V1 to V100 (each has a value of 0 or 1; these 100 variables represent sequ