r - (Excel) 函数根据条件从表中返回特定值
问题描述
我有以下数据:
store location mass target
1 1 (Ams) 45 ?
2 5 (Ber) 500 ?
3 8 (Mar) 1003 ?
在最后一列目标中,我想从表中获取一个值:
location
mass range 1 5 8
0 - 350 3 4 5
> 351 6 7 8
因此,目标列应包含前三行中的值 3、7、8。
我尝试使用函数 INDEX() 但没有成功。如果有人知道如何在 R 或 PowerBI 中执行此操作,那也会对我有所帮助。谢谢!
在 R 中,该示例可通过以下方式重现:
structure(list(Store = 1:3, Location = structure(c(2L, 3L, 1L
), .Label = c("08-Mar", "1 Ams", "5 Ber"), class = "factor"),
Mass = c(1000L, 800L, 500L)), class = "data.frame", row.names = c(NA,
-3L))
和
structure(list(X = structure(1:2, .Label = c("0 - 350", "351 - 1000"
), class = "factor"), X1 = c(3L, 6L), X5 = c(4L, 7L), X8 = c(5L,
8L)), class = "data.frame", row.names = c(NA, -2L))
解决方案
推荐阅读
- javascript - 为什么我不能从 javascript 创建 html?
- r - 在 golem 中添加图标
- vue.js - 图表仅适用于重新加载
- reactjs - React Typescript 钩子错误 - 此表达式不可调用
- python - 循环遍历html标签
- reactjs - history.push() 不会更新浏览器的 url
- node.js - await Promise.all() 返回的结构数组
- google-apps-script - 根据单元格值重命名多个名称范围的 Google App 脚本
- python - 在 Pandas 中合并两个表,并添加多个索引
- watir - 当前在浏览器中设置语言的方式?