r - 如何从命名向量中按名称删除元素?
问题描述
如何按名称从命名向量中删除元素?例如
v <- c(1, 2, 3)
names(v) <- c('a', 'b', 'c')
# how to remove b?
v['b'] <- NULL # doesn't work
Error in v["b"] <- NULL : replacement has length zero
解决方案
你可以使用
v[names(v) != "b"]
#a c
#1 3
或与setdiff
v[setdiff(names(v), "b")]
推荐阅读
- php - 禁用 'phpdoc_var_without_name' 选项 phpcsfixer
- reactjs - 我无法在 Android 的 expo 环境中运行 React Native 应用程序
- python - Pandas 在尝试通过 anaconda 提示符访问 csv 时给出文件未找到错误
- c# - 为什么我不能在 C# 的方法声明中填充数组?
- javascript - Javascript 运行不正常
- python-3.x - 来自字典数据框的数据框
- google-apps-script - 如何保护谷歌表中每个特定用户的范围?
- text - TextNoteType text_size 最小值
- amazon-web-services - 如何通过 AWS CLI 在您的 S3 存储桶上禁用 MFA 删除?
- google-cloud-platform - google_project_services.default:更新服务时出错:googleapi