0

Basically I have a column with signal strength values (Sig_1) and am making a new column called "Activity2". If the difference between one value and the next (of Sig_1) is equal to or more than 5, I would like an "A" to appear in my new column. If the signal strength is below -130, I would like a "W" to appear and if it is above -130 then I would like an "I".

I have a nested ifelse statement:

df <- transform(df, Activity2 = c(0, ifelse(diff(Sig_1)<5), 
ifelse(Sig_1<-130), "W", "I"), "A")

I can't see what's wrong with it but I keep getting:

"Error in ifelse(diff(Sig_1) < 5) :
argument "yes" is missing, with no default"

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user3021648
  • 67
  • 2
  • 3
  • 11

1 Answers1

4

The error is due to wrong brackets: You basically have ifelse(TRUE). Also be careful with the difference between a <- 1 and a < -1. Here's some code that should do what you want:

df <- transform(df, Activity2 = 
ifelse(c(0, diff(Sig_1))<5, ifelse(Sig_1 < -130, "W", "I"), "A"))
shadow
  • 21,823
  • 4
  • 63
  • 77