[R] making a dataframe out of lapply() result

Mahbub Latif ahmlatif at yahoo.com
Wed Apr 16 07:10:28 CEST 2003


you can try this,...
data.frame(t(sapply(tester.L, function(x) x <- x[1,]
)))

Mahbub.

--- Remko Duursma <den.duurs at lycos.com> wrote:
> Dear R-helpers,
> 
> i have a question on how to vectorize this problem:
> 
> i have a dataframe:
> 
> tester <-
> data.frame(groups=c("A","A","B","B","C","C"),
> one=c(1,1,2,2,3,3), two=c(6,6,7,7,8,8))
> 
> # i split it into a list
> tester.L <- split(tester, tester$groups)
> 
> # And want to keep only the first item in each:
> lapply(tester.L, function(x) x <- x[1,] )
> 
> 
> How do i make a dataframe out of the last result,
> which looks like "tester", without looping? (i can
> use rbind in a for loop, but is rather slow)
> 
> thanks for your help,
> 
> Remko Duursma
> 
> 
>
____________________________________________________________
> Get advanced SPAM filtering on Webmail or POP Mail
> ... Get Lycos Mail!
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
>
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


__________________________________________________

The New Yahoo! Search - Faster. Easier. Bingo



More information about the R-help mailing list