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

From: Marc Schwartz <marc_schwartz_at_comcast.net>
Date: Fri, 20 Jun 2008 08:01:23 -0500

on 06/19/2008 11:28 PM Rolf Turner wrote:
>
> 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'').

Unless I missed something in the original request, such that the only column to remove is 'var', why not:

   subset(df, select = -var)

?

See ?subset

HTH, Marc Schwartz



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 - 13:37:05 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:58 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