Re: [R] Named list of data.frames to data.frame with names

2012-10-30 Thread arun
4    A  1.1684286 -0.3849312 #5    A -0.5440966 -0.8001079 #6    B  0.3652238 -0.9604054 A.K. - Original Message - From: Mark Payne To: r-help@r-project.org Cc: Sent: Tuesday, October 30, 2012 4:16 AM Subject: [R] Named list of data.frames to data.frame with names Hi, I very frequently end u

Re: [R] Named list of data.frames to data.frame with names

2012-10-30 Thread Rui Barradas
Hello, You're right, sorry for the misleading post. It's even documented: "|times||A |integer vector giving the (non-negative) number of times to repeat each element if of length |length(x)|" As for a one liner, use within(). within(do.call(rbind, l), name <- rep(names(l), times=sapply(l, nrow

Re: [R] Named list of data.frames to data.frame with names

2012-10-30 Thread Rui Barradas
Hello, There's nothing inelegant in your solution, you're using vectorized instructions. But there's a bug. The argument to rep should be 'each', not 'times'. l2$name <- rep(names(l), each=sapply(l,nrow)) Hope this helps, Rui Barradas Em 30-10-2012 08:16, Mark Payne escreveu: Hi, I very fr

[R] Named list of data.frames to data.frame with names

2012-10-30 Thread Mark Payne
Hi, I very frequently end up in a situation where I have a named list of data.frames that I wish to combine. e.g. l <- list(A=data.frame(x=rnorm(5), y=rnorm(5)), B=data.frame(x=rnorm(3),y=rnorm(3)), C=data.frame(x=rnorm(4),y=rnorm(4)), D=data.frame(x=rnorm(7),y=rnorm