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
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.
The text was updated successfully, but these errors were encountered:
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)
In relation to the post
http://stackoverflow.com/questions/29268941/how-to-split-a-string-variable-in-variables-in-r-non-rectangular/29268972#29268972
it would be convenient and useful if there was a
type.convert
argument to the newtstrsplit()
function, for obvious reasons like easy conversion of numerics as characters to actual numerics after splitting.I was thinking something as simple as
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 inread.table()
so that might not matter.The text was updated successfully, but these errors were encountered: