In R programming I try to do the following:
df
A B Category
0.9 0.85 A
0.7 0.75 B
0.8 0.90 B
CSF <- function(df, type) {
switch(type,
"A" = qnorm(df$A, 0 , 1),
"B" = qnorm(df$B, 0 , 1)
)
}
df<-data.frame(df, value = CSF(df,df$category))
Desired result:
df
A B Category Value
0.9 0.85 A qnorm(0.9, 0, 1)*
0.7 0.75 B qnorm(0.75, 0, 1)*
0.8 0.90 B qnorm(0.9, 0, 1)*
*: real values
Error message: EXPR must be a length 1 vector