[R] performing operations on a dataframe
sayan
kittudg at gmail.com
Fri Nov 6 12:31:39 CET 2009
hey check this
g=x$year
tmp=split(x,g)
tmp1=lapply(tmp,func)
x2=unsplit(tmp1,g)
Lanna Jin wrote:
>
> Hey all,
>
> I feel like the solution to this problem should be relatively simple, but
> for some reason I can't find answers or come up with my own solution.
>
> Given the dataframe:
> (SpA and SpB not important, want to look at distribution of cooccurance
> for
> each year)
>
> Year SpA SpB Coocc
> 2000 0
> 2000 2
> 2000 1
> 2001 8
> 2001 2
> 2001 0
> 2001 0
> 2002 1
> 2002 2
>
> How can I apply different functions to the Coocc of each year?
> (Note: Different lengths for each year, ie,
> length(Year==2000)!=length(Year==2001))
> For example, if Year==2000, function(x) x/146; if Year=2001, function(x)
> x/237; etc.
>
> I've figured out the long convoluted way, but since I plan to operate
> numerous transformations on the different years, is there some way to
> solve
> this in just a few steps?
>
> Thanks for your answer in advance!
>
>
> Lanna
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
>
--
View this message in context: http://old.nabble.com/performing-operations-on-a-dataframe-tp26219957p26230455.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list