[R] Extracting vectors from a matrix (err, I think) in RMySQL

David Winsemius dwinsemius at comcast.net
Wed Dec 2 22:16:40 CET 2009


On Dec 2, 2009, at 4:01 PM, Wells Oliver wrote:

> I have a query which returns a data set like so:
>
>> salaries
>   yearID POS pct
> 1    2009  RF 203
> 2    2009  DH 200
> 3    2009  1B 198
> 4    2009  3B 180
> 5    2009  LF 169
> 6    2009  SS 156
> 7    2009  CF 148
> 8    2009  2B  97
> 9    2009   C  86
> 10   2008  DH 234
> 11   2008  1B 199
> 12   2008  RF 197
> 13   2008  3B 191
> 14   2008  SS 180
> 15   2008  CF 164
> 16   2008  LF 156
> 17   2008  2B 104
> 18   2008   C  98
>
> I'd like to make a vector for all data for a given position, so for  
> example
> here I'd like all yearID a
> nd pct for POS 'RF which should look like:
>

salaries[salaries$POS == 'RF', c("yearID", "pct") ]

First "term" inside the extractor function is a logical index, the  
second specified the columns desired.

>   yearID pct
> 1 2009 203
> 2 2008 197
>
> Apologies if I'm mangling terminology here.
>
> -- 
> Wells Oliver
> wells at submute.net
>
> 	[[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