Displaying 2 results from an estimated 2 matches for "varsplit".
2004 Jul 16
3
Strange (non-deterministic) problem with strsplit
...problem and/or suggest any solutions?
parseFormula <- function(formula) {
splitvars <- function(x) {
strsplit(x, "\\+|\\*")[[1]]
}
stripwhitespace <- function(x) {
gsub("\\s", "", x, perl=T)
}
vars <- stripwhitespace(as.character(formula)[3])
varsplit <- strsplit(vars, "|", fixed=TRUE)[[1]]
parts <- list(
y = stripwhitespace(as.character(formula)[2]),
x = varsplit[1],
g = varsplit[2]
)
lapply(parts, splitvars)
}
Thanks,
Hadley
2004 Jul 16
3
Strange (non-deterministic) problem with strsplit
...problem and/or suggest any solutions?
parseFormula <- function(formula) {
splitvars <- function(x) {
strsplit(x, "\\+|\\*")[[1]]
}
stripwhitespace <- function(x) {
gsub("\\s", "", x, perl=T)
}
vars <- stripwhitespace(as.character(formula)[3])
varsplit <- strsplit(vars, "|", fixed=TRUE)[[1]]
parts <- list(
y = stripwhitespace(as.character(formula)[2]),
x = varsplit[1],
g = varsplit[2]
)
lapply(parts, splitvars)
}
Thanks,
Hadley