Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k views
in Technique[技术] by (71.8m points)

Translating IF condition from Excel to R

I have the following data

A B C D E
1 Date Temp.10 values Criteria
2 10/08/2020 1 0
3 11/08/2020 1 0
4 12/08/2020 1 0 0
5 13/08/2020 1 3 0
6 14/08/2020 1 13 0
7 15/08/2020 1 15 0
8 16/08/2020 1 7 1
9 17/08/2020 1 6 1
10 18/08/2020 1 0 1
11 19/08/2020 1 25 0

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

With dplyr:

library(dplyr)
your_data %>%
  mutate(
    Criteria = ifelse(lag(values, 1) > 5 & lag(values, 2) > 5, 1, 0)
  )

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...