0
votes

My data frame looks like this.

data=data.frame(group=c("A","B","C","A","B","C","A","B","C"), 
                time= c(rep(1,3),rep(2,3), rep(3,3)), 
                value=c(0,1,1,0.1,10,20,10,20,30))

  group time value
1     A    1   0.2
2     B    1   1.0
3     C    1   1.0
4     A    2   0.1
5     B    2  10.0
6     C    2  20.0
7     A    3  10.0
8     B    3  20.0
9     C    3  30.0

I would like to emphasize my search at the time point 1 and based on the values on that time point to filter out the groups that do not fulfil a condition from the later time points.

I would like to delete the values of the groups that on the time point 1 are bigger than 0.5 and smaller than 0.1. I want my data.frame to look like this.

  group time value
1     A    1   0.2
2     A    2   0.1
3     A    3  10.0

Any help is highly appreciated.

1
data shared is not same as data shown. The first value is 0 in your data shared whereas you have shown it as 0.2. - Ronak Shah
You are right @Ronak. I ll edit the question. Thank you for your neat answer as well. - LDT

1 Answers

1
votes

You can select groups where value at time = 1 is between 0.1 and 0.5.

library(dplyr)

data %>%
  group_by(group) %>%
  filter(between(value[time == 1], 0.1, 0.5))

#  group  time value
#  <chr> <dbl> <dbl>
#1 A         1   0.2
#2 A         2   0.1
#3 A         3  10