memy - 10 months ago 63

R Question

My data set is:

`mydata <- data.frame(`

x1= as.factor(1:3),

x2= as.factor (4:6),

x3= as.factor(7:9),

x4= as.factor (2:7),

x5= as.factor(1:6),

fx= seq(0,600,len= 600),

time= seq(0,1,len=600)

)%>%

group_by(x1, x2, x3, x4,x5)

I want to select the points that have the coordinates (time, fx),

that match to the first point of time , the last point of time,

the point in which there is the min(Fx), and half

of intervals points

`(( ( time[[min(fx)]] - time[[1]]/2)+ time [[1]])`

and

`(time[[length(time)]]-time[[min(fx)]]/2)+time[[min(fx)]]))`

is there a way to do it?

Answer Source

You need to use `filter`

, not `select`

(you want to reduce the rows, not the columns). Then, you want to filter based on multiple conditions, so use the logical `or`

operator, which is `|`

. Lastly, to help dplyr along, when doing the `min()`

arguments, include the full dataframe name. This should get you started:

```
mydata %>% filter(time == min(mydata$time)|
time == max(mydata$time)|
fx==min(mydata$fx))
```

I didn't add the other two intervals because I'm not fully sure what you wanted, but perhaps this should help you enough?