[R] Subsetting a data.frame degenerates at one column?
Allen S. Rout
asr at ufl.edu
Fri Feb 8 21:13:15 CET 2008
Greetings.
At the moment, I'm applying R to some AIX 'nmon' output, trying to get
a handle on some disk performance metrics. In case anyone's
interested:
http://docs.osg.ufl.edu/tsm/pdf/
some of them are more edifying than others. (ahem)
I'm trying to develop a somewhat general framework for plotting these
measures, in the hopes that it's of some use to people other than me.
One obstacle I encounter is that, when I select one column out of a
data.frame, the result is no longer a data.frame. So, say I've got,
in data frame 'input'
disk1 disk2 disk3 disk4
T0000 0 1 0 4
T0001 0 1 0 5
T0002 0 1 0 5
T0003 0 2 0 4
T0004 0 2 0 3
T0005 0 1 0 3
T0006 0 0 0 3
and somewhere I've noted a list
targets <- c('disk2','disk3')
I can say
input[,targets]
disk2 disk3
T0000 1 0
T0001 1 0
T0002 1 0
T0003 2 0
T0004 2 0
T0005 1 0
T0006 0 0
but if
targets <- c('disk2')
input[,targets]
[1] 1 1 1 2 2 1 0
Ick.
I've been reading through the indexing and data.frame docs, and remain
unsatisfied so far. Where is my thinking going wrong?
- Allen S. Rout
More information about the R-help
mailing list