list R 将列表转换为小写
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30429039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
R Convert list to lowercase
提问by user6633625673888
Var1 is a list:
Var1 是一个列表:
var1 <- list(c("Parts of a Day", "Time in Astronomy", "Star"), c("Tree Tall", "Pine Tree"))
How to convert all the characters to lowercase? The desired answer is the following list:
如何将所有字符转换为小写?所需的答案是以下列表:
var1 <- list(c("parts of a day", "time in astronomy", "star"), c("tree tall", "pine tree"))
I used
我用了
as.list(tolower(var1))
But it gives the following answer with unwanted \
但它给出了以下不需要的答案\
[[1]]
[1] "c(\"parts of a day\", \"time in astronomy\", \"star\")"
[[2]]
[1] "c(\"tree tall\", \"pine tree\")"
Thanks.
谢谢。
回答by MrFlick
You should use lapply
to lower case each character vector in your list
您应该使用lapply
小写列表中的每个字符向量
lapply(var1, tolower)
# [[1]]
# [1] "parts of a day" "time in astronomy" "star"
#
# [[2]]
# [1] "tree tall" "pine tree"
otherwise tolower
does as.character()
on your entire list which is not what you want.
否则tolower
会出现as.character()
在你的整个列表中,这不是你想要的。
回答by Josh Stevens
Use gsub
用 gsub
gsub("/", "", var1)
as.list(tolower(var1))
this will remove all your / out of your variable.
这将从您的变量中删除所有您的 / 。