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\")"谢谢。
发布于 2015-05-25 06:38:19
您应该使用lapply将列表中的每个字符向量小写
lapply(var1, tolower)
# [[1]]
# [1] "parts of a day" "time in astronomy" "star"
#
# [[2]]
# [1] "tree tall" "pine tree"否则,tolower会对你的整个列表执行as.character(),这不是你想要的。
发布于 2015-05-25 06:39:55
使用gsub
gsub("/", "", var1)
as.list(tolower(var1))这将从变量中删除所有的/。
https://stackoverflow.com/questions/30429039
复制相似问题