0

I have a data frame that is similar to this small sample:

Tree  variable  value
 1      x1       0       
 2      x2       1
 3      x3       0
 4      x1       2
 5      x2       1
 6      x3       1

My question is:

How do I extract, say, just the x1 values and make it a data frame?

I'm not sure if this requires an if statement or if there's a better way in R to do this?

Any advice is greatly appreciated.

Electrino
  • 2,636
  • 3
  • 18
  • 40

1 Answers1

1

Base R

df[df$variable == "X1",]

dplyr

library(dplyr)
df %>%
  filter(variable == "x1")
DSGym
  • 2,807
  • 1
  • 6
  • 18