Re: [R] function recode within sapply

2011-10-02 Thread Joshua Wiley
Hi Lara, Use lapply here instead of sapply or specify simplify = FALSE. See ?sapply for details. d[, c("fac1", "fac2")] <- lapply(d[, c("fac1", "fac2")], recode, "c('A', 'B') = 'XX'", as.factor.result = TRUE) d[, "fac3"] <- recode(d[, "fac3"], "c('A', 'B') = 'XX'") str(d) Cheers, Josh On Sun,

[R] function recode within sapply

2011-10-02 Thread Lara Poplarski
Dear List, I am using function recode, from package car, within sapply, as follows: L3 <- LETTERS[1:3] (d <- data.frame(cbind(x = 1, y = 1:10), fac1 = sample(L3, 10, replace=TRUE), fac2 = sample(L3, 10, replace=TRUE), fac3 = sample(L3, 10, replace=TRUE))) str(d) d[, c("fac1", "fac2")] <- sapply(