[英]Convert a data frame into 1/0s
I have a data frame of 166 people which I would like to convert to a binary matrix.我有一个 166 人的数据框,我想将其转换为二进制矩阵。 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我只是想知道我可以使用什么代码将其转换为二进制,即 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.