Skip to content
Prev 310362 / 398506 Next

General function to substitute values in a data frame

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,12,13)
z <- c(28,29,30,31)
dat <- data.frame(y,z)

apply(dat, 2, replace.letter, first = 10)


Also, the use of attach() is disadvised, it can be confusing.

Hope this helps,

Rui Barradas

Em 09-11-2012 09:33, Fabricius Domingos escreveu: