applying the excel function on R studio data frame

I am trying to apply the some kind of calculation in dataframe in R

df <- data.frame("T1" = c(327,512,634),
                 "T2"= c(873,654,968),
                 "CT" = c(5,5,4))

for example i am applying in excel below, i want to mutate new column without changing original data

T1 T2 CT form
415 659 5 1
0 0 5
2 0 5
0 0 5
0 0 5
in form column D2
=IF((B4>=100)*(C4>=3)*(IFERROR(A4/B4,0))>=0.05,1,0)

Does the code below give the logic you want. Notice that I changed your df data so that some zeros would be returned.

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
df <- data.frame("T1" = c(327,512,634),
                 "T2"= c(873,0,968),
                 "CT" = c(5,5,2))

df <- df %>% mutate(NewCol = ifelse(T2 !=0 & T2 >= 100 & CT >= 3 & T1/T2 > 0.05, 1, 0))
df
#>    T1  T2 CT NewCol
#> 1 327 873  5      1
#> 2 512   0  5      0
#> 3 634 968  2      0

Created on 2021-04-19 by the reprex package (v0.3.0)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.