the following seems to work for numeric but not for times: parse.vec <- function (vec, parser = as.numeric, vmode = "numeric", na.string = "N/A") { bad <- (vec == na.string); ret <- vector(mode = vmode, length = length(vec)); if (some(bad)) ret[bad] <- NA; if (some(!bad)) ret[!bad] <- parser(vec[!bad]); ret; }
data[[2]] <- parse.vec(data[,2]); # works! but not with times: parse.vec(df$Time, vmode = "list", na.string = "<invalid time>", parser = function (s) strptime(s,format = "%H:%M:%OS")); Warning message: In ret[!bad] <- strptime(vec[!bad], format = "%H:%M:%OS") : number of items to replace is not a multiple of replacement length why? (just in case: > length(ret) [1] 2022 > length(vec) [1] 2022 > length(bad) [1] 2022 > all(!bad) [1] TRUE -- Sam Steingold (http://sds.podval.org/) on CentOS release 5.3 (Final) http://mideasttruth.com http://jihadwatch.org http://truepeace.org http://dhimmi.com http://memri.org http://pmw.org.il http://camera.org If it has syntax, it isn't user friendly. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.