How to subset() from data frame using specific rows
Hi
On Wed, 5 Oct 2011, Petr PIKAL wrote:
Hm. I seldom use such approach. In your original request you said you
want
split your data to smaller data frames based on sites
Petr, I need the additional information in the database, too.
But you do not loose them, your data frame is cut according to sites variable and put into a list see
iris.spl<- split(iris, iris$Species) str(iris.spl)
List of 3 $ setosa :'data.frame': 50 obs. of 5 variables: ..$ Sepal.Length: num [1:50] 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... ..$ Sepal.Width : num [1:50] 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
From what we know it is difficult to say if there is some common
feature
in site variable. If it is organised like XY-N you can simply make new variable from first two letters
Unfortunately, the site designations are not so uniform. As I went
through
the process of re-doing the data I discovered this lack of consistency resulting in duplicate records because one site had been designated XX-n
and
XXn. Had to clean those up, too.
sites <- substr(chemdata$site,1,2)
Which would not matter if the first two letters designates required grouping variable I called sites Regards Petr
then you can split your data frame according to sites chem.spl <- split(chemdata, sites) and do anything with your splitted data frames organised in list
First thing this morning I'm upgrading to 2.13.2 and hoping that this fixes an issue that just showed up yesterday afternoon: not being able
to
access function help pages. For example, I tried ?subset and ?split
because
I thought the latter is really what I want, yet R told me no help was
found.
Strange; it was there a week ago. Thanks, Rich
______________________________________________ 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.