Используя Base R, найдите ответ
df <- read.table(text=" score ID
1 32 1.2
2 35 1.3
3 20 2.1
4 15 3.2 ",header= T)
Ответ: -
df$c1 <- ifelse(length(unique(substr(df$ID,1,1))) == 1,"Yes","No")
df$c2 <- ifelse((substr(df$ID,3,3)) == max(substr(df$ID,3,3)),"Yes","No")
# Create the function as Mode is not directly available in R ##
getmode <- function(v) {
uniqv <- unique(v)
uniqv[which.max(tabulate(match(v, uniqv)))]
}
df$c3 <- ifelse(substr(df$ID,1,1) == getmode(substr(df$ID,1,1)),"Yes","No")
result <- structure(list(score = c(32L, 35L, 20L, 15L), ID = c(1.2, 1.3,
2.1, 3.2), c1 = c("No", "No", "No", "No"), c2 = c("No", "Yes",
"No", "No"), c3 = c("Yes", "Yes", "No", "No")), row.names = c("1",
"2", "3", "4"), class = "data.frame")