Is this what you want:

> yrData <- data.frame(year=sample(1990:2000, 100, TRUE),
+     species=sample(1:3,100,TRUE), loc=sample(1:2,100,TRUE))
> byYear <- split(yrData, yrData$year)
>
> byYear[1:3]
$`1990`
   year species loc
39 1990       3   2
57 1990       3   1
62 1990       1   1
68 1990       2   1
71 1990       2   2
80 1990       3   2
85 1990       3   2
90 1990       3   2
93 1990       2   1
$`1991`
   year species loc
9  1991       2   2
19 1991       3   2
21 1991       1   2
22 1991       3   1
25 1991       2   2
30 1991       1   1
54 1991       1   1
65 1991       1   1
79 1991       2   2
84 1991       3   1
91 1991       2   1
98 1991       2   1
$`1992`
   year species loc
4  1992       2   1
5  1992       1   2
15 1992       2   2
16 1992       2   1
32 1992       3   2
75 1992       1   2
95 1992       3   1



On Wed, Mar 10, 2010 at 12:07 PM, Lanna Jin <lannajin@gmail.com> wrote:

> Hi All,
>
> If given a dataframe (long form) with Year, Species, and Location,
> How would I write a function that would create a unique matrix of Species &
> Location for each Year?
>
> What I've tried doing is the following:
>
> data #dataframe
> dataT<-table(data$Species,data$Location,data$Year) #creates tables of
> Species vs Location for each Year
>
> But I'm encountering issues individually indexing the tables and converting
> them into matrices in one fell swoop.
>
> r1997<-as.matrix(tableT[,,"1997"]) #How I would do it individually; but I
> can I make matrices for each year as a function?
>
> Thanks in advance for your suggestions!
>
> --
> Lanna Jin
>
> lannajin@gmail.com
> 510-898-8525
>
>        [[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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

	[[alternative HTML version deleted]]

