如何在Excel中类似于vlookup查找某个值?以及如何使用 for 循环创建数据框?

发布于 2025-01-09 21:50:00 字数 285 浏览 2 评论 0原文

我有两个数据框都有 2 列(2 个变量)。

我在想我可以在excel中使用类似于vlookup的东西吗? 也许我可以使用 for 循环创建一个新的数据集,并将商放入该数据集中,但我不知道具体该怎么做。

(我还需要将值放入数据集中,因此建议的帖子不能完全回答我的问题)

示例:

dataframe1
number amount
 1  2
 2  3
 3  4


dataframe2
number amount
 1  5
 2  6
 4  2
   
 

I have two dataframes both have 2 columns (2 variables).

I was thinking that I could use something similar to vlookup in excel?
And maybe I could create a new dataset using for loop and put the quotients in this dataset I don't know how exactly I could do that.

(I ALSO NEED TO PUT THE VALUES IN A DATASET so the suggested post does not answer my question completely)

example:

dataframe1
number amount
 1  2
 2  3
 3  4


dataframe2
number amount
 1  5
 2  6
 4  2
   
 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灼疼热情 2025-01-16 21:50:00

假设您将 Dataframe1 导入为 Dataframe1,将 Dataframe2 导入为 Dataframe2,并且两者都是 data.frame

library(tidyverse)
Dataframe1 %>%
  inner_join(Dataframe2 %>% rename(Amount2 = Amount),
             by="id") -> Dataframe

此时,您可以执行操作

library(tidyverse)
Dataframe %>%
  mutate(result = Amount/Amount2) -> Dataframe

并检查结果列是否是您要查找的内容。

找到最高比率:

Dataframe$result %>% max(na.rm = T)

但是还有很多其他方法来记录这个值;这是最直接的。

Assuming that you imported Dataframe1 as Dataframe1, and Dataframe2 as Dataframe2, and both are data.frame.

library(tidyverse)
Dataframe1 %>%
  inner_join(Dataframe2 %>% rename(Amount2 = Amount),
             by="id") -> Dataframe

At this point you can perform your operation

library(tidyverse)
Dataframe %>%
  mutate(result = Amount/Amount2) -> Dataframe

and check if the column result is what you were looking for.

To find the highest ratio:

Dataframe$result %>% max(na.rm = T)

But there are many other ways to record this value; this is the most straightforward.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文