[R] Splitting a dataframe by character vector
Ben Neal
bneal at spg.ucsd.edu
Sat Apr 21 03:52:24 CEST 2012
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). I just want to generate summary statistics for my other variables for each site individually.
I know this should be simple, and I did read up on options, choosing to use "subset", but I am honestly confounded that this does not result in a new dataframe split by this factor. I tried "subset" with an argument based on my various other numeric vectors, and it worked just fine. My very simple code is below, and thank you for any responses. I apologize for asking such a simple question, but I wrote this out exactly as found it in an exactly similar question, which indicated this should work. Now I am confused! Thank you for any assistance. Ben Neal
# Load data from CSV file
Cover = read.csv ("/Users/benjaminneal/Documents/1110_Panama/Transect series /1210_BocasTransectSummary.csv",
header=T)
# Divide dataframe by Site names
Site1 <- subset(Cover, Site = "PtaCaracol")
PS The csv loads fine, gives normal summary stats, and does not seem to be the issue. I thought about just renaming by hand all the sites in the file (i.e. "PtaCaracol"=1 . . but this seems like a weak solution).
More information about the R-help
mailing list