A base R
опция будет table
tbl <- +(table(c(col(df1[-1])), unlist(df1[-1]) ) > 0)
cbind(df1[1], as.data.frame.matrix(tbl))
Или с использованием tidyverse
library(tidyverse)
rownames_to_column(df1, 'rn') %>%
gather(key, val, var1:var4) %>%
count(rn, val) %>%
spread(val, n, fill = 0) %>%
select(-rn) %>%
bind_cols(df1[1], .)
data
df1 <- structure(list(Value1 = c(9.330154398, 32.43881489, 54.77178387,
54.77178387), var1 = c("HomeATL", "AwaySDN", "AwayLAN", "AwayLAN"
), var2 = c("AwayHOU", "HomeATL", "HomeATL", "HomeATL"), var3 = c("HomeEast",
"HomeWest", "AwayEast", "AwayWest"), var4 = c("AwayWest", "AwayWest",
"HomeSame", "HomeEast")), class = "data.frame", row.names = c(NA,
-4L))