x <- data.frame(d=letters[1:3], e=letters[3:5])
lookuptable <- c(a="aa", c="cc", e="ee")
match.or.keep <- function(x, lookuptable) {if (is.factor(x)) x <- as.character(x);
m <- match(x, names(lookuptable)); ifelse(is.na(m), x, lookuptable[m])}
# to return a matrix
apply(x, 2, match.or.keep, looku
On Oct 5, 2009, at 4:47 PM, Jill Hollenbach wrote:
Let me clarify:
I'm using this--
dfnew<- sapply(df, function(df) lookuptable[match(df, lookuptable [ ,
1]),
2])
It seems a very bad idea to use the same name in your functions as
that of the dataframe argument you might be passing. You
Let me clarify:
I'm using this--
dfnew<- sapply(df, function(df) lookuptable[match(df, lookuptable [ ,1]),
2])
>lookup
0101 01:01
0201 02:01
0301 03:01
0401 04:01
>df
0101 0301
0201 0401
0101 0502
>dfnew
01:01 03:01
02:01 04:01
01:01 NA
but what I want is:
>dfnew2
01:01
On 6/10/2009, at 9:01 AM, Jill Hollenbach wrote:
Hi all,
I think this is a very basic question, but I'm new to this so
please bear
with me.
I'm using match to translate elements of a data frame using a
lookup table.
If the content of a particular cell is not found in the lookup
table,
On Oct 5, 2009, at 4:01 PM, Jill Hollenbach wrote:
Hi all,
I think this is a very basic question, but I'm new to this so please
bear
with me.
I'm using match to translate elements of a data frame using a lookup
table.
If the content of a particular cell is not found in the lookup
table
Hi all,
I think this is a very basic question, but I'm new to this so please bear
with me.
I'm using match to translate elements of a data frame using a lookup table.
If the content of a particular cell is not found in the lookup table, the
function returns NA. I'm wondering how I can just ignore
6 matches
Mail list logo