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

2012-11-09 Thread arun
day, November 9, 2012 4:33 AM Subject: [R] General function to substitute values in a data frame Hi R users, I need a way to substitute the values 10:31 to the letters A:V (i.e 10=A, 11=B, ..., 31=V) in a data frame. For example: > y<-c(10,11,12,13) > z<-c(28,29,30,31) > df<-da

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

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

2012-11-09 Thread Fabricius Domingos
Hi R users, I need a way to substitute the values 10:31 to the letters A:V (i.e 10=A, 11=B, ..., 31=V) in a data frame. For example: > y<-c(10,11,12,13) > z<-c(28,29,30,31) > df<-data.frame(y,z) > df y z 1 10 28 2 11 29 3 12 30 4 13 31 Then I would substitute it and obtain a data frame like