Var1是一个列表:
var1 <- list(c("Parts of a Day", "Time in Astronomy", "Star"), c("Tree Tall", "Pine Tree"))
如何将所有字符转换为小写?所需的答案是以下列表:
var1 <- list(c("parts of a day", "time in astronomy", "star"), c("tree tall", "pine tree"))
我用过
as.list(tolower(var1))
但是它给出了以下答案,并带有不必要的\
[[1]]
[1] "c(\"parts of a day\", \"time in astronomy\", \"star\")"
[[2]]
[1] "c(\"tree tall\", \"pine tree\")"
谢谢。
您应该使用lapply
小写列表中的每个字符向量
lapply(var1, tolower)
# [[1]]
# [1] "parts of a day" "time in astronomy" "star"
#
# [[2]]
# [1] "tree tall" "pine tree"
否则,tolower
在整个列表上都将as.character()
放在了您想要的位置上。
使用gsub
gsub("/", "", var1)
as.list(tolower(var1))
这将从您的变量中删除所有/。