Re: [R] Redefine multiple columns (using grep) as factor variables

2012-06-01 Thread Rui Barradas
I've made a mistake, I should have used 'lapply' not 'sapply' DF <- make.df() str(DF) DF[, ix] <- lapply(DF[, ix], as.factor) str(DF)# crast1: Factor w/ 4 levels I should have looked further... Rui Barradas Em 01-06-2012 10:10, Rui Barradas escreveu: Hello, Sorry, I've just answered to

Re: [R] Redefine multiple columns (using grep) as factor variables

2012-06-01 Thread Rui Barradas
Hello, Sorry, I've just answered to Johannes without Cc to r-help. Repeat: See the difference. # helper function make.df <- function(){ x <- as.data.frame(matrix(1:24, ncol=6)) names(x) <- c(paste0("crast", 1:2), "A", "B", paste0("crast", 5:6)) x } DF <- make.df() (ix <- grep("^cr

[R] Redefine multiple columns (using grep) as factor variables

2012-06-01 Thread Johannes Radinger
Hi, I have a dataframe with around 100 columns. Now I want to redefine some of the columns as factors (using as.factor). Luckily all the names of the columns I want to redefine start with "crast". Thus I thought I can use grep() for that purpose... ...I found an example for redefining a single co