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
382 views
in Technique[技术] by (71.8m points)

how to segregate in R using if condition


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

1 Answer

0 votes
by (71.8m points)

A base R option using ifelse

transform(
  df,
  B = ifelse(A>200,A,NA),
  C = ifelse(A<=200,A,NA)
)

gives

    A   B   C
1 250 250  NA
2 190  NA 190
3 100  NA 100
4 500 500  NA
5 400 400  NA

Data

df <- data.frame(A = c(250,190,100,500,400))

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

...