You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Please add a "type.convert" argument to tstrsplit() #1094
it would be convenient and useful if there was a type.convert argument to the new tstrsplit() function, for obvious reasons like easy conversion of numerics as characters to actual numerics after splitting.
I was thinking something as simple as
tstrsplit <- function(..., fill = NA, type.convert = TRUE) {
x <- transpose(strsplit(...), fill = fill, ignore.empty = FALSE)
if(type.convert) lapply(x, type.convert, as.is = TRUE) else x
}
x <- c("", "1-7-9", "3", "2-4-6-8")
tstrsplit(x, "-", fixed = TRUE)
# [[1]]
# [1] NA 1 3 2
#
# [[2]]
# [1] NA 7 NA 4
#
# [[3]]
# [1] NA 9 NA 6
#
# [[4]]
# [1] NA NA NA 8
But I'm not sure how your internals work and might be better-off done internally. Of course, other things to think about are the other arguments to type.convert(), but they aren't available in read.table() so that might not matter.
Also maybe add simplify argument too in case you want a matrix back instead of a list (though it's not a problem when within the data.table parent frame)
Activity
arunsrinivasan commentedon Mar 26, 2015
Also convert from
factortocharacterby default as spotted by @rmscriven here.DavidArenburg commentedon Mar 26, 2015
Also maybe add
simplifyargument too in case you want a matrix back instead of a list (though it's not a problem when within thedata.tableparent frame)