Re: [R] Re shaping a dataframe with conditional summary of columns - apply or reshape?

From: David Hewitt <dhewitt37_at_gmail.com>
Date: Thu, 24 Jan 2008 13:55:57 -0800 (PST)

> Try this:
>
> 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.



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--tp15058600p15075986.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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 24 Jan 2008 - 21:59:39 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 24 Jan 2008 - 22:30:09 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