Re: [R] Data frame index?

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Wed 18 Jan 2006 - 19:58:41 EST

you could try something like the following:

dat <- data.frame(matrix(rnorm(200), 20, 10)) index <- sample(10, 20, TRUE)
###############
mat.ind <- matrix(FALSE, nrow(dat), length(dat)) mat.ind[cbind(seq(along = index), index)] <- TRUE dat[mat.ind] <- 0

index
dat

I hope it helps.

Best,
Dimitris



Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


> Hi, R users:
>
> I have a data.frame (not a matrix), I got a vector with the same
> length
> as the
> number of records (rows) of the data frame, and each element of
> that vector is the column number (in a specific range of columns) of
> the
> corresponding
> record that I must set to zero.
>
> How can I do this without a "for" loop?
>
> Thank you for your help.
>
> Kenneth
>
>


> ______________________________________________
> 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

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



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 Received on Wed Jan 18 20:28:58 2006

This archive was generated by hypermail 2.1.8 : Wed 18 Jan 2006 - 22:24:54 EST