Re: [R] Finding the position of a variable in a data.frame

From: John Kane <jrkrideau_at_yahoo.ca>
Date: Fri 04 Aug 2006 - 08:38:51 EST

> You don't need to find out the column index. This
> works:
>
> Df[5,'bat'] <- 100
>
> -Don
>

Thanks, I'd tried
Df[5, bat] <- 100 :(

I never thought of the ' ' being needed.

> At 5:01 PM -0400 8/2/06, John Kane wrote:
> >Simple problem but I don't see the answer. I'm
> trying
> >to clean up some data
> >I have 120 columns in a data.frame. I have one
> value
> >in a column named "blaw" that I want to change. How
> do
> >I find the coordinates. I can find the row by doing
> a
> >subset on the data.frame but how do I find out here
> >"blaw " is in columns without manually counting
> them
> >or converting names(Df) to a list and reading down
> the
> >list.
> >
> >Simple example
> >
> >cat <- c( 3,5,6,8,0)
> >dog <- c(3,5,3,6, 0)
> >rat <- c (5, 5, 4, 9, 0)
> >bat <- c( 12, 42, 45, 32, 54)
> >
> >Df <- data.frame(cbind(cat, dog, rat, bat))
> >Df
> >subset(Df, bat >= 50)
> >
> >----results
> > cat dog rat bat
> >5 0 0 0 54
> >
> >
> >Thus I know that my target is in row 5 but how do I
> >figure out where 'bat' is?
> >
> >All I want to do is be able to say
> >Df[5,4] <- 100
> >
> >Is there some way to have function(bat) return the
> >column number: some kind of a colnum() function? I
> >had thought that I had found somthing in
> >library(gdata) matchcols but no luck.
> >
> >______________________________________________
> >R-help@stat.math.ethz.ch 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.
>
>
> --
> --------------------------------------
> Don MacQueen
> Environmental Protection Department
> Lawrence Livermore National Laboratory
> Livermore, CA, USA
> --------------------------------------
>



R-help@stat.math.ethz.ch 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 Aug 04 08:46:34 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 04 Aug 2006 - 12:17:25 EST.

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