[R] How to recode a factor level (within the list)?
Lauri Nikkinen
lauri.nikkinen at iki.fi
Sun Dec 2 18:53:55 CET 2007
#Dear R-users,
#I have a data.frame like this:
y1 <- rnorm(10) + 6.8
y2 <- rnorm(10) + (1:10*1.7 + 1)
y3 <- rnorm(10) + (1:10*6.7 + 3.7)
y <- c(y1,y2,y3)
x <- rep(1:3,10)
f <- gl(2,15, labels=paste("lev", 1:2, sep=""))
g <- seq(as.Date("2000/1/1"), by="day", length=30)
DF <- data.frame(x=x,y=y, f=f, g=g)
DF$g[DF$x == 1] <- NA
DF$x[3:6] <- NA
DF$wdays <- weekdays(DF$g)
DF
#Frequences
g <- lapply(DF, function(x) as.data.frame(table(format(x))))
g
#NA:s are now part of factor levels. How to recode NA:s into e.g. "missing"?
#Thanks
#Lauri
More information about the R-help
mailing list