首页 > 解决方案 > 我如何将字符串计数为R中的数字

问题描述

再会,

我是 R 的初学者,我正在尝试从多个值中添加一些字符串。例如,我得到了 2 个值;

NominationsGrammyAwards <- c("Grammy Award For best Videoclip", "Song of the Year", "Best Rap Performance", "Best Rap Song", "Best Music Video")

NominationBETAward <- "Video Of The Year"

总共有 6 个字符串,但我如何才能将它放在一个数字 6 中。例如,我想将它们加在一起,形成一个名为 TotalNominations 的值。像这样:

TotalNominations <- (Which code?)

我用 sapply 尝试了一些东西,但是没有用。谁能帮帮我?

谢谢!

标签: rstring

解决方案


尝试length

NominationsGrammyAwards <- c("Grammy Award For best Videoclip", "Song of the Year", "Best Rap Performance", "Best Rap Song", "Best Music Video")

NominationBETAward <- "Video Of The Year"

length(NominationsGrammyAwards)
#> [1] 5

length(NominationBETAward)
#> [1] 1

reprex 包(v0.3.0)于 2020-12-07 创建

编辑 1 以添加它们:

a <- NominationsGrammyAwards <- c("Grammy Award For best Videoclip", "Song of the Year", "Best Rap Performance", "Best Rap Song", "Best Music Video")

b <- NominationBETAward <- "Video Of The Year"

length(a) + length(b)
#> [1] 6

reprex 包(v0.3.0)于 2020-12-07 创建


推荐阅读