[R] Extracting a column name in loop?

Mark Knecht markknecht at gmail.com
Wed Jul 8 18:53:09 CEST 2009


On Wed, Jul 8, 2009 at 8:41 AM,
mister_bluesman<mister_bluesman at hotmail.com> wrote:
>
> Hi,
>
> I am writing a script that will address columns using syntax like:
>
> data_set[,1]
>
> to extract the data from the first column of my data set, for example. This
> code will be placed in a loop (where the column reference will be placed by
> a variable).
>
> What I also need to do is extract the column NAME for a given column being
> processed in the loop. The dataframe has been set so that R knows that the
> top line refers to column headers.
>
> Can anyone help me understand how to do this?
>
> Thanks.

Possibly something like

names(data_set)[i]

?

HTH,
Mark




More information about the R-help mailing list