[R] Replacing columns in a data frame using a previous condition

2008-02-14 Thread Jorge Iván Vélez
Dear R-list, I'm working with a data frame which dimensions are > dim(GERU) [1] 3468 318 and looks like > GERU[1:10,1:10] ped ind par1 par2 sex sta rs7696470 rs7696470.1 rs1032896 rs1032896.1 1 USA5854 200 2 1 4 4 1 1 2 USA5854 3

Re: [R] Replacing columns in a data frame using a previous condition

2008-02-14 Thread Jorge Iván Vélez
It's, Jim. Thank you so much. Jorge On 2/14/08, jim holtman <[EMAIL PROTECTED]> wrote: > > Is this what you want to do? > > > x <- data.frame(a=1:10, b=1:10, c=1:10, d=1:10) > > z <- cbind(c=11:20, d=11:20) > > z > c d > [1,] 11 11 > [2,] 12 12 > [3,] 13 13 > [4,] 14 14 > [5,] 15 15 > [6,

Re: [R] Replacing columns in a data frame using a previous condition

2008-02-14 Thread jim holtman
Is this what you want to do? > x <- data.frame(a=1:10, b=1:10, c=1:10, d=1:10) > z <- cbind(c=11:20, d=11:20) > z c d [1,] 11 11 [2,] 12 12 [3,] 13 13 [4,] 14 14 [5,] 15 15 [6,] 16 16 [7,] 17 17 [8,] 18 18 [9,] 19 19 [10,] 20 20 > x[,colnames(z)] <- z[, colnames(z)] > x a b

[R] Replacing columns in a data frame using a previous condition (SOLVED)

2008-02-14 Thread Jorge Iván Vélez
Dear R-list, Thanks a lot for your help. Thanks to Jim, Dimitris and Phil. It's exactly what I needed to do. Jorge On 2/14/08, Jorge Iván Vélez <[EMAIL PROTECTED]> wrote: > Dear R-list, > > I'm working with a data frame which dimensions are > > > dim(GERU) > [1] 3468 318 > > and looks like >

Re: [R] Replacing columns in a data frame using a previous condition

2008-02-14 Thread Dimitris Rizopoulos
try this: GERU[6:318] <- lapply(GERU[6:318], function (x) { if (length(unique(x[!is.na(x)])) >= 5) x[x == 2] <- 3 x }) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijn