0

Sorry for very simple question, but I have a reference table with two columns : code and description:

gear = structure(list(`Gear Code` = c(101, 102, 103, 104, 105, 106, 
107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 
120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 
133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 
146, 147, 148, 149, 150), `Gear Description` = c("NORPAC (North Pacific Standard Net)", 
"Plankton Net (Muslin)", "Plankton Net (Silk)", "Marutoku B Net", 
"JUDAY Net - OLD DO NOT USE", "JUDAY Oceanic Model (JOM)", "Ring Net", 
"Gulf IA Sampler", "Gulf III Sampler", "Gulf II Sampler", "Rectangular Midwater Trawl (RMT)", 
"Plankton Net (type not specified)", "Be' Multiple Plankton Sampler (MPS)", 
"Bathypelagic Plankton Sampler (BPS)", "Indian Ocean Standard Net (IOSN)", 
"Clarke-Bumpus Sampler", "Neuston Net", "Bongo Net", "Water Pump (type not specified)", 
"MOCNESS (Multiple Opening and Closing Nets and Environment Sampling System)", 
"BR 80/113 Net", "CPR (Longhurst-Hardy)", "Isaacs-Kidd Midwater Trawl (IKMT)", 
"Midwater Trawl", "ORI-C Net", "Kitahara(n) Net", "Bottle (type not specified)", 
"Bottle (Niskin)", "Marutoku Net (not specified)", "Bottle (Go-Flo)", 
"CalCOFI Net", "WP-2 (UNESCO Working Party 2)", "Nansen Surface Net", 
"Heron Tranter Net", "N70 - Discovery pattern N70 net", "Organdie Net", 
"75M25 Net", "TSK (model not specified)", "Hensen Net", "Beam Trawl", 
"Marushi Net", "Foredeck Net", "Motoda Horizontal Net (MTD)", 
"Van Dorn Bottle", "General Oceanics Model 2030", "POFI Net", 
"Micro Net (not specified)", "Open Net (not specified)", "Closing Net (not specified)", 
"High Speed Net (type not specified)")), row.names = c(NA, -50L
), class = c("tbl_df", "tbl", "data.frame"))

Then I have another dataframe with the following column:

df_column = c("111", "111", "112", "112", "139", "141", "140, "143", "102", 
"112", "115", "117")

I want to replace each number in the df_column with the Description from a gear data frame.

I know I can use left_join function to match two data frames, but it will add an extra column, and I would like to avoid it

yuliaUU
  • 1,581
  • 2
  • 12
  • 33

1 Answers1

1

If you join the dataframes, you can remove the columns later if they are not needed. Anyway, since df_column is a vector you can try match which will not add an extra column in the first place.

data.frame(description=gear$`Gear Description`[match(df_column,gear$`Gear Code`)])

#                         description
#1   Rectangular Midwater Trawl (RMT)
#2   Rectangular Midwater Trawl (RMT)
#3  Plankton Net (type not specified)
#4  Plankton Net (type not specified)
#5                         Hensen Net
#6                        Marushi Net
#7                         Beam Trawl
#8        Motoda Horizontal Net (MTD)
#9              Plankton Net (Muslin)
#10 Plankton Net (type not specified)
#11  Indian Ocean Standard Net (IOSN)
#12                       Neuston Net
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213