Re: [R] Howto access V-base only column in a data frame

From: Rolf Turner <r.turner_at_auckland.ac.nz>
Date: Fri, 20 Jun 2008 16:28:33 +1200

On 20/06/2008, at 4:07 PM, Moshe Olshansky wrote:

> If you know the value of k then you could do the following:
>
> goodNames <- paste("V",1:k,sep="")
> ind <- which(colnames(df) %in% goodNames)
> df[,ind]
>
> (where df is your dataframe).
>
> P.S. I won't be surprised if df[,goodNames] is all right too (have
> not checked).

What about df[,grep("^V",names(df))] ? (Leave off the ``^'' if you want any
column whose name contains ``V'' (r.t. begins with ``V'').

        cheers,

                Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

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. Received on Fri 20 Jun 2008 - 06:11:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 20 Jun 2008 - 14:30:57 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive