r - 遍历存储在向量中的值
问题描述
在下面有代码,我试图找出唯一的区域名称然后迭代,但是当我运行它时它只打印出 1 行。
这是我的代码:
ZonelistName<-unique(temp[c("zone")])
#this is where the LSD for the zone will be
for (p in c(ZonelistName)) {
print(p)
}
打印出来:
# > [1] 3 2 5 1
dput(head(ZonelistName))
structure(list(zone = c(3, 2, 5, 1)), row.names = c(NA, -4L), class = c("tbl_df",
"tbl", "data.frame"))
抱歉,我无法复制它,因为我不知道那个对象是什么
解决方案
我想你可能需要unlist
而不是c
for (p in unlist(ZonelistName)) {
print(p)
}
或者
for (p in ZonelistName$zone) {
print(p)
}
这使
[1] 3
[1] 2
[1] 5
[1] 1
推荐阅读
- android - Intent Action_Call 在我的应用程序中不起作用
- trackjs - Trackjs:通过用户代理中的令牌忽略规则
- javascript - material-ui 背景 - 因无效的钩子调用而失败
- c# - c# VS 错误列表消息缺少错误代码和文件名参考
- javascript - IBM Cognos 10.2 展开/折叠功能
- javascript - Chrome 扩展 - 仅在用户登录后加载 JS
- c - 如何在c上获得正确的输出
- flutter - Dart Analysis Server 服务器在过去 3 分钟内崩溃了 5 次。服务器不会重启
- python - 自动化 Java GUI,在 RDP 上运行
- javascript - 从字符串创建 JavaScript 对象