[R] Fwd: Re: extracting index list when using tapply()

From: <ctu_at_bigred.unl.edu>
Date: Tue, 08 Jul 2008 14:55:16 -0500

The following message is provided by Erik

Please provide the reproducible code to do this. Generate a sample data set using the random data generating functions and show us what you'd like, we can then more easily help.

ctu_at_bigred.unl.edu wrote:
> Hi,
> How about using "subset"?
> x1<-tapply(subset(years, length(area)>20), function(x) length(unique(x)))
>
> I hope this works
> Chunhao
>
>
> Quoting hesicaia <dboyce_at_dal.ca>:
>
>>
>> Hello,
>> The quick version of my question is how can I extract a matrix instead of
>> a vector using tapply()? I would like to be able to access both the results
>> of tapply() and also the index variables.
>>
>> In case further explanation would help: I am analyzing a large (3million
>> rows x 9 columns) spatial/temporal dataset and am attempting to calculate
>> the number of unique years containing any data within each geographic area
>> (10 degree cells in this case). I can do this, but I also want to extract a
>> subset vector of the index variable (area).
>>
>> My script to calculate the number of unique years containing any data for
>> each area is:
>> x<-tapply(years, area, function(x) length(unique(x)))
>>
>> Now, I want to extract the vector of areas where the number of unique years
>> containing any data is >20, but tapply() only returns a vector of unique
>> years and I was a matrix.

>>
>> I could use a looping function to do this, but tapply() is much faster with
>> large datasets and so I would like to use it if possible.
>>
>> Any help is appreciated.
>> Thanks.
>> --
>> View this message in context:
>> http://www.nabble.com/extracting-index-list-when-using-tapply%28%29-tp18345794p18345794.html Sent from the R help mailing list archive at
>> Nabble.com.
>>
>> ______________________________________________
>> R-help_at_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.
>>
>
> ______________________________________________
> R-help_at_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.


R-help_at_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. Received on Tue 08 Jul 2008 - 20:26:54 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 08 Jul 2008 - 20:33:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive