Re: [R] change values in data frames

2008-06-28 Thread Kenn Konstabel
Another way to do it (a more or less straightforward translation of what you said): fun <- function(x) { xp <- c("", x)[-(length(x)+1)] # to get the "previous element of x" x[1] <- if(x[1]=="i") "l" else x[1] x <- ifelse(x == "i" & xp == "c", "l", x) x <- ifelse(x == "i" &

Re: [R] change values in data frames

2008-06-28 Thread poul
Thanks a lot, it works perfectly . Bye Paul jholtman wrote: > > Is this what you want: > >> x > cola colb > 11c > 21i > 31i > 41c > 52i > 62c > 72c > 82i > 92i >> # generate run lengths >> z <- rle(x$colb) >> # calculat

Re: [R] change values in data frames

2008-06-27 Thread jim holtman
Is this what you want: > x cola colb 11c 21i 31i 41c 52i 62c 72c 82i 92i > # generate run lengths > z <- rle(x$colb) > # calculate offset of each starting sequence > offsets <- head(cumsum(c(1, z$lengths)), -1) > # now deter

[R] change values in data frames

2008-06-27 Thread poul
Hello every body, I am quite a new user of R so I beg your pardon for this naive question and the lake of syntax with wich I ask it: I have a data frames like this: colacolb 1 c 1 i 1 i 1 c 2 i 2 c 2 c 2 i 2 i ... 1 I would like ,for