Re: [R] General function to substitute values in a data frame

2012-11-09 Thread arun
HI, May be this: res<- data.frame(apply(df,2,function(x) ifelse(grepl("\\d+",x),LETTERS[x-9],NA))) res #  y z #1 A S #2 B T #3 C U #4 D V #or  apply(df,2,function(x) LETTERS[x-9]) A.K. - Original Message - From: Fabricius Domingos To: r-help@r-project.org Cc: Sent: Friday, November

Re: [R] General function to substitute values in a data frame

2012-11-09 Thread Rui Barradas
Hello, Try the following. I've changed the name of your data.frame to 'dat', 'df' is an R function. replace.letter <- function(x, first = 1, upper = TRUE){ if(upper) LETTERS[x - first + 1] else letters[x - first + 1] } replace.letter(10:31, first = 10) y <- c(10,11,1

Re: [R] General function to substitute values in a data frame

2012-11-09 Thread Gerrit Eichner
Hello, Fabricius, does as.data.frame( lapply( df, function( x) LETTERS[ x-9])) what you want? Other (here maybe less flexible) ways: transform( df, y = LETTERS[y - 9], z = LETTERS[ z - 9]) within( df, {y <- LETTERS[y - 9]; z <- LETTERS[ z - 9]}) Hth -- Gerrit On Fri, 9 Nov 2012, F