[R] Selecting biological data
David Winsemius
dwinsemius at comcast.net
Sat Sep 5 18:13:23 CEST 2009
On Sep 5, 2009, at 11:58 AM, John Casey wrote:
>
> Hello all,
> I am new to R but have some experience with MATLAB and am trying
> to make the switch. I generally find the two languages easy to adapt
> but there are a few routine tasks which I would like to run smoother
> in R and I am having trouble finding a help resource. Could someone
> suggest a guide to filtering, selecting, sorting, and processing
> biological matrix data? Here is a rudimentary example of what I'm
> after [ocean research cruise- data.frame<-example]:
>
> Cruise, dec yr, station, cast, depth, data1
> 1, 2007.65, 9, 29, 1, 105.04
> 1, 2007.65, 9, 29, 10, 104.91
> 1, 2007.65, 9, 29, 20, 101.43
> 1, 2007.65, 9, 29, 50, 100.68
> 1, 2007.65, 9, 29, 100, 100.09
> 1, 2007.69, 11, 33, 1, 107.32
> 1, 2007.69, 11, 33, 10, 105.94
> 1, 2007.69, 11, 33, 20, 102.19
> 1, 2007.69, 11, 33, 50, 101.27
> 1, 2007.69, 11, 33, 100, 100.15
>
> Let's say I would like to select data1 from cast 33 at 1, 20, and
> 100m depth... how would I go about this?
?subset
subset(df1, cast==33 & depth %in% c(1,20,100) )
... or since your specification was vague;
subset(df1, cast==33 & depth==1 )
subset(df1, cast==33 & depth==20 )
subset(df1, cast==33 & depth==100 )
Also:
?"["
# the first column specification can be a logical vector, as in
df1[df1$col1 == 20, ] and will return subsets. But subset function is
nicer in that you don't have precede each column name by the dataframe
name.
And of course:
>
> Thanks in advance for helping out a greenhorn!
> John
>
>
> _________________________________________________________________
>
> Facebook.
>
> :ON:WL:en-US:SI_SB_facebook:082009
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list