[R] Splitting a dataframe by character vector
S Ellison
S.Ellison at LGCGroup.com
Mon Apr 23 12:19:45 CEST 2012
> -----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}}
More information about the R-help
mailing list