[R] How to subset() from data frame using specific rows

Petr PIKAL petr.pikal at precheza.cz
Wed Oct 5 08:29:42 CEST 2011


> 
> On Tue, 4 Oct 2011, Sarah Goslee wrote:
> 
> > You asked for pointers, and didn't provide a reproducible example, so 
I
> > offered a pointer.
> 
> Sarah,
> 
>    I did not realize that your pointer was to the factor component of 
the
> subset() command.
> 
>    I think the most parsimonious thing for me to do is to modify the 
database
> table with a new column of the full stream name, then re-export and 
re-read
> into R.

Hm. I seldom use such approach. In your original request you said you want 
split your data to smaller data frames based on sites 

-----
   I need to create subsets (as data frames) based on sites, but including
all sites on each stream. For example, using the initial site factor shown
------

>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

sites <- substr(chemdata$site,1,2)

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

Regards
Petr

> 
> 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.



More information about the R-help mailing list