'How to find certain value similar to vlookup in excel? And how to create dataframe with for loop?
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
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
