Hi, I'm trying to return the names of variables in a dataframe which meet a certain criteria. I get a resulting list but could use help getting the names which meet length = 1 (I'm looking for variables which have unique values of just 1 or length of 1, that is, zero variance)
x1 <- c("T", "T", "T", "T", "T", "T", "F", "F", "F", "N")
x2 <- c("A", "A", "A", "A", "A", "A", "A", "A", "A", "A")
x3 <- c(1,2,3,4,5,6,7,8,9,10)
x4 <- c(1,2,3,4,5,6,7,8,9,10)
d <- data.frame(x1,x2,x3,x4)
v <- d %>% colnames
d1 <- lapply(d[v], unique)
d2 <- lapply(d1[v], length)
d3 <- names(d2)[lapply(d2[v] == 1)] ??
The output should be x2
Thanks in advance for help from smart people