MrPapouille
MrPapouille

Reputation: 39

If in a data.frame

I would like to choose a value between two columns in the same row following values in other columns.

My function would be like: if values inside shapiro1, shapiro2 and F_test are less than 0.05 choose value in t_test else choose wilcox's value. Does it seem possible to you to make a function like this and apply on a larger columns?

structure(list(modalities = structure(1:3, .Label = c("BS1", 
"HW1", "PG"), class = "factor"), shapiro1 = c(0.0130672654432492, 
0.305460485386201, 0.148320635833262), shapiro2 = c(0.920315823302857, 
0.1354174735521, 0.148320635833262), F_test = c(0.20353475323665, 
0.00172897172228584, 1), t_test = c(2.88264982135322e-06, 5.75374264225996e-05, 
NaN), wilcox = c(0.00909069801592506, 0.00902991076269246, NaN
)), class = "data.frame", row.names = c(NA, -3L))

Upvotes: 0

Views: 72

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 389265

You could select columns, apply rowSums and check if any value in that row is less than 0.05 and select t_test or wilcox values accordingly.

cols <- c("shapiro1", "shapiro2", "F_test")
ifelse(rowSums(df[cols] < 0.05) > 0, df$t_test, df$wilcox)
#[1] 2.882650e-06 5.753743e-05          NaN

Upvotes: 1

Related Questions