[R] Subsetting a data.frame degenerates at one column?
Henrique Dallazuanna
wwwhsd at gmail.com
Sat Feb 9 19:03:32 CET 2008
Try this also:
input[targets]
On 08/02/2008, Allen S. Rout <asr at ufl.edu> wrote:
>
> 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
>
> ______________________________________________
> 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.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
More information about the R-help
mailing list