Thanks a lot. That worked perfectly.
 
Best,Farnoosh Sheikhi

________________________________


Sent: Wednesday, August 28, 2013 10:37 AM
Subject: Re: list to data frame


If the expected result is data.frame()


 as.data.frame(t(as.data.frame(lapply(dat1,sum))))# would be data.frame.  But, 
not sure why you need this when you are trying for a histogram.






________________________________


Sent: Wednesday, August 28, 2013 1:33 PM
Subject: Re: list to data frame



I think Data frame.

Best,Farnoosh Sheikhi


________________________________


Sent: Wednesday, August 28, 2013 10:08 AM
Subject: Re: list to data frame


Also, you haven't mentioned what is the expected data format..



----- Original Message -----


Cc: R help <r-help@r-project.org>
Sent: Wednesday, August 28, 2013 1:07 PM
Subject: Re: list to data frame

Hi,
set.seed(249)
dat1<- as.data.frame(matrix(sample(1:20,40*20,replace=TRUE),ncol=20))

#Based on your code:
 vecNew<-sort(t(as.data.frame(lapply(dat1,sum))),decreasing=TRUE)[1:10]

#or
vec1<-sort(unlist(lapply(dat1,sum),use.names=FALSE),decreasing=TRUE)[1:10]
 identical(vec1,vecNew)
#[1]
TRUE


#Instead of using the ?lapply(),
vec2<-setNames(sort(colSums(dat1),decreasing=TRUE)[1:10],NULL)
 identical(as.numeric(vec1),vec2)
#[1] TRUE
A.K.





________________________________


Sent: Wednesday, August 28, 2013 12:35 PM
Subject: list to data frame



Hi there,

I have a data set and I want to get the sum of each column. Then order the 
result from high to low and draw a histogram for the top 10.

I was trying to use lapply(data, sum), but the result is in a list and even 
after changing to data frame
and get the transpose, I can't get the right data format.

test<-as.data.frame(lapply(data, sum))
test<-t(test)

Thanks for your help.

Best,Farnoosh Sheikhi  
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to