[R] Extracting vectors from a matrix (err, I think) in RMySQL
jim holtman
jholtman at gmail.com
Wed Dec 2 23:50:15 CET 2009
try this:
> 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
> x <- split(salaries[c('yearID','pct')], salaries$POS)
> x
$`1B`
yearID pct
3 2009 198
11 2008 199
$`2B`
yearID pct
8 2009 97
17 2008 104
$`3B`
yearID pct
4 2009 180
13 2008 191
$C
yearID pct
9 2009 86
18 2008 98
$CF
yearID pct
7 2009 148
15 2008 164
$DH
yearID pct
2 2009 200
10 2008 234
$LF
yearID pct
5 2009 169
16 2008 156
$RF
yearID pct
1 2009 203
12 2008 197
$SS
yearID pct
6 2009 156
14 2008 180
>
On Wed, Dec 2, 2009 at 4:01 PM, Wells Oliver <wells at submute.net> 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 and pct for POS 'RF which should look like:
>
> 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help
mailing list