Re: [R] field index given name.

2009-10-12 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of tdm > Sent: Monday, October 12, 2009 12:22 AM > To: r-help@r-project.org > Subject: Re: [R] field index given name. > > > Thanks - would never have

Re: [R] field index given name.

2009-10-12 Thread David Winsemius
On Oct 12, 2009, at 3:22 AM, tdm wrote: Thanks - would never have guessed that. I eventually got the following to do what I want... colprob <- array(dim=NCOL(iris)) for(i in 1:NCOL(iris)){ + colprob[i]= + ifelse(names(iris)[i] == 'Species',1,0.5) + } colprob [1] 0.5 0.5 0.5 0.5 1.0

Re: [R] field index given name.

2009-10-12 Thread tdm
Thanks - would never have guessed that. I eventually got the following to do what I want... > colprob <- array(dim=NCOL(iris)) > for(i in 1:NCOL(iris)){ + colprob[i]= + ifelse(names(iris)[i] == 'Species',1,0.5) + } > colprob [1] 0.5 0.5 0.5 0.5 1.0 Schalk Heunis-2 wrote: > > Hi Phil > Try th

Re: [R] field index given name.

2009-10-12 Thread Schalk Heunis
Hi Phil Try the following > which(names(iris)=='Species') [1] 5 HTH Schalk Heunis On Mon, Oct 12, 2009 at 8:53 AM, tdm wrote: > > Hi, > > How do I access the index number of a field given I only know the field > name? > > eg - I want to set the probability of the field 'species' higher than the

[R] field index given name.

2009-10-11 Thread tdm
Hi, How do I access the index number of a field given I only know the field name? eg - I want to set the probability of the field 'species' higher than the other fields to use in sampling. > colprob <- array(dim=NCOL(iris)) > for(i in 1:NCOL(iris)){colprob[i]=0.5} > colprob[iris$species] = 1 #t