R将列表转换为小写

时间:2015-05-24 22:36:36

标签: r list lowercase

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\")"

感谢。

2 个答案:

答案 0 :(得分:29)

您应该使用sapply来降低列表中每个字符向量的大小写

sapply(var1, tolower)

# [[1]]
# [1] "parts of a day"    "time in astronomy" "star"             
# 
# [[2]]
# [1] "tree tall" "pine tree"

否则tolower会在您的整个列表中显示as.character(),这不是您想要的。

答案 1 :(得分:1)

使用gsub("/", "", var1) as.list(tolower(var1))

startActivityForResult()

这将删除您的所有变量。

相关问题