[R] Split a list
David Winsemius
dwinsemius at comcast.net
Fri Oct 14 15:58:43 CEST 2011
On Oct 14, 2011, at 9:26 AM, Weidong Gu wrote:
> It would be nice if you could provide a sample.
That is certainly true.
> However, if the data
> in the list have the same colnames, you can combine them by
>
> df<-do.call('rbind',your_list_data_frame)
>
> Then you can do what you want on the dataframe instead of a list
>
> HTH
>
> Weidong Gu
>
>
> On Fri, Oct 14, 2011 at 9:06 AM, Juliet Ndukum <jpntsang at yahoo.com>
> wrote:
>> I have a list of dataframes i.e. each list element is a dataframe
>> with three columns and differing number of rows. The third column
>> takes on only two values. I wish to split the list into two
>> sublists based on the value of the third column of the list element.
Perhaps something like:
list_of_firsts <- lapply(dflist, function(x) X[ , X[,3]=="first"] )
list_of_seconds <- lapply( dflist, function(x) X[ , X[,3]=="second"])
Ow with subset (but without that missing example it is more difficult
to show the true value of subset:
subset(X, select= X[,3]=="first")
>> Second issue with lists as well. I would like to reduce each of the
>> sublist based on the range of the second column, i.e. if the range
>> of the second column is greater than twenty for example keep the
>> list element.
Same as above with an inequality sign.
>>
>> Could someone help me with a code to implement these two issues.
>> Thanks in advance for your help,
>> JN
>> [[alternative HTML version deleted]]
>
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list