Perfect, thanks all. Unlist and ave will both be very handy functions to
know. -levi
--
Levi Waldron, PhD
Treated Wood Research Group
Faculty of Forestry, University of Toronto
33 Willcocks Street, Toronto ON, M5S 3B3 CANADA
Tel 647-866-5384
Fax 416-978-3834
[[alternative HTML versio
Try this:
df$wildo <- ave(df$x, df$fac, FUN = cumsum)
On Fri, Jun 27, 2008 at 4:52 PM, Levi Waldron <[EMAIL PROTECTED]> wrote:
> This one should be easy but it's giving me a hard time mostly because tapply
> puts the results in a list. I want to calculate the cumulative sum of a
> variable in a
On Fri, 2008-06-27 at 16:52 -0400, Levi Waldron wrote:
> This one should be easy but it's giving me a hard time mostly because tapply
> puts the results in a list. I want to calculate the cumulative sum of a
> variable in a dataframe, but with the accumulation only within each level of
> a factor.
Just use ?unlist
df$willdo <- unlist(tapply(df$x, df$fac, cumsum))
df$ideal <- df$willdo - df$x
Levi Waldron wrote:
This one should be easy but it's giving me a hard time mostly because tapply
puts the results in a list. I want to calculate the cumulative sum of a
variable in a dataframe, but
This one should be easy but it's giving me a hard time mostly because tapply
puts the results in a list. I want to calculate the cumulative sum of a
variable in a dataframe, but with the accumulation only within each level of
a factor. For a very simple example, take:
> df <-
data.frame(x=c(rep(
5 matches
Mail list logo