Skip to content
Prev 310455 / 398506 Next

as.data.frame(do.call(rbind, lapply)) produces something weird

HI,
If you don't want to list the column names explicitly,
you can try this:
?z1<-as.data.frame(do.call(rbind,lapply(1:3,function(x) c(a=paste("a",x,sep=""),unlist(do.call(c,list(b=myfun(x),c=myfun(x*x*x))))))))
z2<-z1[,-1]
?z2[]<-sapply(z2,function(x) as.numeric(as.character(x))) 
data.frame(a=z1[,1],z2)
#?? a b.x b.y c.x c.y
#1 a1?? 1?? 1?? 1?? 1
#2 a2?? 2?? 4?? 8? 64
#3 a3?? 3?? 9? 27 729
?str(data.frame(a=z1[,1],z2))
#'data.frame':??? 3 obs. of? 5 variables:
# $ a? : Factor w/ 3 levels "a1","a2","a3": 1 2 3
# $ b.x: num? 1 2 3
# $ b.y: num? 1 4 9
# $ c.x: num? 1 8 27
# $ c.y: num? 1 64 729

A.K.

----- Original Message -----
From: Sam Steingold <sds at gnu.org>
To: r-help at r-project.org; arun <smartpink111 at yahoo.com>
Cc: 
Sent: Friday, November 9, 2012 3:00 PM
Subject: Re: as.data.frame(do.call(rbind, lapply)) produces something weird
1. I don't want to have to list all the column names explicitly

2. I find the num->char->num conversion repugnant and unacceptable.