-1

I have following data frame and I would like to extract the value of the second column (tools) based on the value of the first column (barcode).

004041  FLASHLIGHT  SUREFIRE    GX2 - TACTICAL  UNK B-3 
004044  FLASHLIGHT  SUREFIRE    G2X TACTICAL    NONE    D-3 1/11/17 
004045  FLASHLIGHT  SUREFIRE    GX2 - TACTICAL  UNK D-3 
004045  TACTICAL LIGHT  SUNFIRE 4045    D-3 1/17/18 
004048  FLASHLIGHT  SUREFIRE    G2X TACTICAL    NONE    D-3 1/11/17 
004272  35' TAPE MEASURE    STANLEY 

For example if I have a barcode of 004041 I would like the code to return FLASHLIGHT.

Philipp HB
  • 171
  • 1
  • 14
  • 1
    Hey, welcome to SO. If you follow these instructions https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example , you are way more likely to get an answer as it will clear up any confusion about your data. – Chabo May 25 '18 at 18:30
  • I'm sure someone on here can help, don't panic as I had little to no experience at my first job when they wanted me to write R. You'll be surprised what you can code with a bit of research and some willpower. – Chabo May 25 '18 at 18:33
  • 2
    something like this? `df[df$barcode == "004044",2]` – acylam May 25 '18 at 18:33
  • Can you show what the expected result would look like? What are variables (columns) here? – Roman Luštrik May 25 '18 at 18:41

1 Answers1

1

You could try two things:

  1. Using core R:

    df[df$barcode == "004041",2]
    
  2. Using the dplyr package:

    library(dplyr)
    df %>% filter(barcode == "004041") %>% select(tools)
    

Hope this helps!

Philipp HB
  • 171
  • 1
  • 14