12

I have the following given:

TR  Avg RE
3   0
3   0
4   209.3524872
3   185.6542898
3   0
3   0
3   0
4   136.7522375
4   157.6887675
4   0
3   202.8994858
3   0
3   89.45242983
4   0
3   0
3   218.4987273
3   192.4212849

I want to extract only those values of RE where TR is equal to 4 - how can I do that?

zx8754
  • 52,746
  • 12
  • 114
  • 209
Pugl
  • 432
  • 2
  • 5
  • 22

1 Answers1

19

You already have the answer from David's comment. However, for interest below is few additional methods to do it.

Code:

# Method 1:
df[df$TR == 4, "RE"]

# Method 2:
df[ which(df$TR == 4), "RE"]

# Method 3:
subset(df$RE, df$TR == 4)

# Method 4: You could also use the sqldf package to use sql
# install.packages("sqldf")
library(sqldf)
sqldf('select RE from df where TR = 4')
Manohar Swamynathan
  • 2,065
  • 21
  • 23