>> x$survey1[x$count==0] <- 0
>> x$survey1[x$count %in% 1:11] <- 1
>> x$survey1[x$count > 11] <- 2
>>  x.wide <- reshape(x, v.names="survey1", idvar="location",
>> timevar="survey1", direction="wide")
>> x.wide <- x.wide[order(x.wide$location),]
>> x.wide$var1 <- tapply(x$var1, x$location, mean)
>> x.wide
> 
> Thanks a lot Henrique. Only needed two simple changes:
> (1) Made the range in the second assignment 1:10 and the operator in the
> second > 10 to conform with the rules I needed.
> (2) Changed "timevar" from "survey1" to "survey". Using "survey1"
> reordered the columns for the survey observations, and it was much easier
> to have survey1 first, survey2 second, and survey3 third.
> 

Oops, spoke too soon. Should have put this in the example, but the locations
can be replicated in subsequent years (observations from the same place
through time), so reshape drops all but the first. Any ideas?


-----
David Hewitt
Virginia Institute of Marine Science
http://www.vims.edu/fish/students/dhewitt/
-- 
View this message in context: 
http://www.nabble.com/Reshaping-a-dataframe-with-conditional-summary-of-columns---apply-or-reshape--tp15058600p15076251.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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
and provide commented, minimal, self-contained, reproducible code.

Reply via email to