'Using any() within if statement on dataframe columns

I have a dataframe name ffq_long with 2 columns. "ffqnum" "orig_freq1"
num double

I am trying to calculate a new column base on some value in orig_freq1 I have no problem doing it using a logical statement

ffq_long$orig_freq2<- ifelse(orig_freq1==1.5 | orig_freq1==3.5 | orig_freq1== 5.5 , orig_freq1 * (30 / 7),orig_freq1 )

On the other hand I don’t find a way to do it using any() function. I tried the 4 flowing statement, and all give the same mistake. And all of them evaluate to TRUE while the values of orig_freq1 are 0; 2; 1.5; 3.5; 5.5; 30; 75; 135; 180

ffq_long$orig_freq2<- ifelse(as.integer(any(orig_freq1,1.5,3.5,5.5)) ,30 / 7,11 )

ffq_long$orig_freq3<- if(any(orig_freq1,1.5,3.5,5.5) ) orig_freq1 * (30 / 4) else 8

ffq_long$orig_freq4<- if(as.numeric(any(orig_freq1,1.5,3.5,5.5) )) (30 / 3) else 5

ffq_long$orig_freq5<- as.numeric(ifelse(any(orig_freq1,1.5,3.5,5.5) , 30 / 2 ,22))

Warning message: In any(orig_freq1, 1.5, 3.5, 5.5) : coercing argument of type 'double' to logical

Is there a way to use any() or an equivalent for that goal .



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source