Skip to content
Prev 326264 / 398502 Next

Recoding variables based on reference values in data frame

Hello,

If you have read in the data as factors (stringsAsFactors = TRUE, the 
default), change the function to the following.


fun <- function(x){
	x[x %in% c("nc", "_")] <- NA
	MM <- paste0(as.character(x[1]), as.character(x[1]))  # Major Major
	Mm <- paste0(as.character(x[1]), as.character(x[2]))  # Major minor
	mm <- paste0(as.character(x[2]), as.character(x[2]))  # minor minor
	x[x == MM] <- 0
	x[x == Mm] <- 1
	x[x == mm] <- 2
	x
}



Rui Barradas

Em 02-07-2013 22:15, Rui Barradas escreveu: