How to do vlookup with R

Hi,

I have 2 tables different sizes
the first one small, example:

tibble::tribble(
~Item, ~'0', ~'1',
"123", '30', '40',
"213", '20', '50',
"321", '10', '60',
)

The other one is huge with Item names and a description of the item, example:

tibble::tribble(
~Item, ~'something1', ~'something2', ~'Description', 
"123", 'xxx', 'xxx',  'Description1',
"213", 'xxx', 'xxx', 'Description2',
"321", 'xxx', 'xxx', 'Description3',
)

Description column is the one I want to add to the small table, the first example

You'll likely use merge() or some equivalent.

This allows you to link your two tables by a similar variable, in this case it would be Item.

how do I specify that I only want the Description column?

This is one way to go about it in R. You could use other data-management packages to produce the same result with better legibility or better memory efficiency.

df_1 <- tibble::tribble(
~Item, ~'0', ~'1',
"123", '30', '40',
"213", '20', '50',
"321", '10', '60',
)

df_2 <- tibble::tribble(
~Item, ~'something1', ~'something2', ~'Description', 
"123", 'xxx', 'xxx',  'Description1',
"213", 'xxx', 'xxx', 'Description2',
"321", 'xxx', 'xxx', 'Description3',
)

df_3 <- merge(x = df_1, y = df_2[,c(1,4)], by = "Item")

Again huge thanks, really appreciate you taking the time

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.