Re: [R] Read data in sequences

2010-04-11 Thread Gabor Grothendieck
Here it is in function form: > # DF is data frame > # k is number of levels > # ids is a vector of column numbers of id variables > > read.reps <- function(DF, k = 2, ids = 1) { + n <- prod(dim(DF[-ids])) / k # no of rows of output + m <- ncol(DF[-ids])/k # no of reps per line + data.frame(id =

Re: [R] Read data in sequences

2010-04-11 Thread RockO
Gabor's elegant method works as well indeed where gl(number of factor level,number of replications): > data.frame(id = dat[gl(3,4),1], t(matrix(t(dat[-1]), 2))) Rock DRF-MRNF, Quebec -- View this message in context: http://n4.nabble.com/Read-data-in-sequences-tp1819487p1836285.html Sent from t

Re: [R] Read data in sequences

2010-04-11 Thread RockO
Hi, Thank you very much for your help! Here is the coding I used to make it work: x <- textConnection("A 2.5 3.4 2.7 5.6 5.7 5.4 10.1 9.4 B 5.3 5.4 6.5 7.5 1.3 4.5 10.5 4.1 C 2.1 2.3 2.1 5.4 9.0 4.5 20.1 3.7") dat <- read.table(x) nv <- 2 # Number of variables that are repe

Re: [R] Read data in sequences

2010-04-10 Thread Gabor Grothendieck
Try this. The data portion DF[-1] is transposed forming length 2 columns composed of successive elements of DF rows. This is then transposed back and the id's added in: # read in Lines <- "A 2.5 3.4 2.7 5.6 5.7 5.4 10.1 9.4 B 5.3 5.4 6.5 7.5 1.3 4.5 10.5 4.1" DF <- read.table(textConnection(Lin

Re: [R] Read data in sequences

2010-04-10 Thread Peter Ehlers
On 2010-04-09 10:04, Dieter Menne wrote: RockO wrote: I tried to find a solution in the search list, but I cannot find it. I would like to read a .txt file with, let say, three variables, with two of which have repeated values in a number a columns. The variables: Treat, x1, x2. The values:

Re: [R] Read data in sequences

2010-04-09 Thread Phil Spector
Rock - Here's one way: x = textConnection('A 2.5 3.4 2.7 5.6 5.7 5.4 10.1 9.4 + B 5.3 5.4 6.5 7.5 1.3 4.5 10.5 4.1') dat = read.table(x) names(dat) = c('grp','x1','x2','x3','x4','x5','x6','x7','x8') reshape(dat,idvar='grp',varying=list(c('x1','x3','x5','x7'), +

[R] Read data in sequences

2010-04-09 Thread RockO
Dear R users, I tried to find a solution in the search list, but I cannot find it. I would like to read a .txt file with, let say, three variables, with two of which have repeated values in a number a columns. An example: The variables: Treat, x1, x2. The values: A 2.5 3.4 2.7 5.6 5.7 5.4 10.1

Re: [R] Read data in sequences

2010-04-09 Thread Dieter Menne
RockO wrote: > > I tried to find a solution in the search list, but I cannot find it. I > would like to read a .txt file with, let say, three variables, with two of > which have repeated values in a number a columns. > > The variables: Treat, x1, x2. > The values: > A 2.5 3.4 2.7 5.6 5.7 5.4 1