【发布时间】:2022-01-06 08:24:45
【问题描述】:
我注意到函数 strsplit() 和 scan() 处理下划线的方式不同,我想知道为什么会这样。
请考虑以下示例代码:
x1 <- "string split"
strsplit(x1, " ")[[1]]
# [1] "string" "split"
scan(text = x1, what = " ")
# [1] "string" "split"
strsplit 和 scan 使用 " " 作为分隔符的输出是一样的。
但是,当我使用“_”作为分隔符时,输出是不同的:
x2 <- "string_split"
strsplit(x2, "_")[[1]]
# [1] "string" "split"
scan(text = x2, what = "_")
# [1] "string_split"
为什么使用下划线作为分隔符时strsplit和scan的输出不同?
【问题讨论】:
-
what不是分隔符,而应该是文本的类。
标签: r string function character