Thanks Steve, your explanation of the "==" is very helpful, and I will look up 
?by. Ben 


-----Original Message-----
From: S Ellison [mailto:s.elli...@lgcgroup.com]
Sent: Mon 4/23/2012 3:19 AM
To: Ben Neal; r-help@r-project.org
Subject: RE: Splitting a dataframe by character vector
 
 

> -----Original Message-----
> I am just trying to split a dataframe of 750 observations of 
> 29 variables by "Site", which is a vector in the dataframe 
> with five text names (ex. PtaCaracol). 
A couple of methods.
i) First, look up ?split, which chops your data frame into a list of five data 
frames. Then use lapply on the list to get a list of summaries, or sapply to 
get something that will (if the results of your summary are a simple number or 
vector) look like an array.

ii) look up ?by, which will do something like lapply (and returns a list with 
extra features) and will print a tidier result.

> I tried "subset" ....
> # Divide dataframe by Site names
> Site1 <- subset(Cover, Site = "PtaCaracol")

Check your syntax again; that should have been
 Site1 <- subset(Cover, Site == "PtaCaracol")

'=' is a pairwise link or an assignment operator, not the equality test that 
subset would be looking for. 

Steve E
*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}

______________________________________________
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