-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
In relation to the post
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.
Reactions are currently unavailable