r - 我如何将字符串计数为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 尝试了一些东西,但是没有用。谁能帮帮我?
谢谢!
解决方案
尝试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 创建
推荐阅读
- jquery - 分页问题 - 同一页面上有多个数据表
- ruby-on-rails - Rails 4:异常站点(#70058148983820)预期,得到字符串(#8388700)
- memory - 如何为多实例配置 Odoo 内存使用?
- macos - 为什么“msbuild”命令不会将其输出重定向到预览应用程序,而“man”命令会?
- python - 确定最大和最小像素值以绘制边界框
- javascript - 如何将对象作为函数的参数传递而不会出现意外标识符错误?
- android - Kivy android 希腊字符
- scala - sbt.ResolveException:未解决的依赖项:org.glassfish.hk2#hk2-utils;2.22.2:未找到
- python - 尝试连接到太多 websocket 时出错
- dart - TextFormString 验证器的多行字符串