I have a data frame of 166 people which I would like to convert to a binary matrix. So in the data frame it looks like the following:
I am just wondering what code could I use to convert this to binary ie 1/0s
A = absent
N = no
Y = yes
All for votes
Any help would be appreciated !
I've just created some sample data, If I understand what you are looking for correctly -
df <-matrix(sample(c("a","n","y"),166*20, replace = TRUE),166,20)
df[df == "a"]=NA
df[df == "y"]= 1
df[df == "n"] = 0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.