Re: [R] Storing output in an array or matrix

From: Erik Iverson <iverson_at_biostat.wisc.edu>
Date: Thu, 06 Mar 2008 13:40:11 -0600

I think you could get this done with the function "tapply", but it's not clear because you don't give an example of your data. If tapply is not the answer, certainly there is a way that is better than resorting to doing it 'by hand' (brute force).

See ?tapply

Best,
Erik Iverson

tieflingrogue wrote:
>
>
> I have a data set which has, let's say, income by state. I'm trying to
> output income quartiles for each state into an array by doing a loop so that
> I don't have to do it state by state by hand.
>
> ie, something like
>
> for (i in 1:50) {
>
> quantile(subset(data,state==i)$income) -> r[i,5] }
>
>
> where the output of quantile will give 5 columns for each state. r would
> be a 50x5 matrix where each row represents state i's income quartiles.
>
> thanks



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 Thu 06 Mar 2008 - 19:44:25 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 Thu 06 Mar 2008 - 20:30:19 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