Hi! I'm trying to create a variable that will let me know if an individual row has an SD below a certain cutoff. The SD cutoff is very high here because most of my data is good. Right now the issue is that I'm getting a column for SD with a very long name, and all my NFC.flag and flag.count variables are showing as 1 even though they shouldn't be based on the data.
Here is my data set:
DF_NFC <- data.frame(
NFC1 = c(4, 5, 2, 4, 2, 1),
NFC2 = c(5, 5, 3, 4, 4, 1),
NFC3 = c(4, 4, 2, 3, 4, 2),
NFC4 = c(5, 4, 3, 1, 4, 1),
NFC5 = c(4, 5, 4, 3, 4, 3),
NFC6 = c(4, 4, 4, 4, 4, 2),
NFC7 = c(5, 4, 2, 3, 2, 3),
NFC8 = c(2, 4, 4, 1, 3, 1),
NFC9 = c(5, 4, 4, 2, 4, 1),
NFC10 = c(5, 5, 2, 5, 4, 1),
NFC11 = c(4, 5, 1, 2, 4, 1),
NFC12 = c(4, 4, 4, 2, 5, 2),
NFC13 = c(5, 4, 3, 5, 4, 3),
NFC14 = c(4, 5, 4, 4, 4, 3),
NFC15 = c(5, 4, 4, 3, 4, 1),
NFC16 = c(4, 3, 2, 2, 3, 1),
NFC17 = c(5, 4, 4, 4, 5, 3),
NFC18 = c(4, 5, 3, 5, 3, 2)
)
Here is the current code:
t <- 1 #sd threshold
NFCflag <- DF_NFC %>%
rowwise() %>%
mutate((NFC.sd = sd(c_across(NFC1:NFC18))),
NFC.flag = case_when(abs(NFC.sd) >= t ~ 0,
abs(NFC.sd) < t ~ 1),
flag.count = sum(c(NFC.flag)))