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

From: Moshe Olshansky <m_olshansky_at_yahoo.com>
Date: Thu, 19 Jun 2008 21:07:50 -0700 (PDT)


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).

> From: Gundala Viswanath <gundalav_at_gmail.com>
> Subject: [R] Howto access V-base only column in a data frame
> To: r-help_at_stat.math.ethz.ch
> Received: Friday, 20 June, 2008, 1:27 PM
> Hi,
>
> Suppose I have the following data frame:
>
> V1 V2 V3 var
> 1 100 200 400 2.3
> 2 40.5 1.2 20.3
> ...
>
> In this example the maximum V column is 3.
> In my code there the column number can be varied.
>
> My question is how can I access data frame
> from column V1 up to Vk (some "k" and
> excluding'var' column)?
>
> - Gundala Viswanath
> Jakarta - Indonesia
>
> ______________________________________________
> 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.



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 - 04:13:39 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 - 06:31:24 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