[R] Data frame index?

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.be
Wed Jan 18 09:58:41 CET 2006


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


----- Original Message ----- 
From: "Kenneth Cabrera" <krcabrer at epm.net.co>
To: <r-help at stat.math.ethz.ch>
Sent: Wednesday, January 18, 2006 8:35 AM
Subject: [R] Data frame index?


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




More information about the R-help mailing list