我收到一个EXCEL文件,如下所示:
structure(list(`Variable Name` = c("form.hhConsent", NA, NA,
"form.hhReasonRefused", NA, NA, NA, "form.childrenRepeat.childrenGroup.childSex",
NA, NA, "form.childrenRepeat.childrenGroup.dobSourceWho", NA,
NA, NA, NA, "form.hohSex", NA, NA, "form.mothersRepeat.mothersGroup.spouseSex",
NA, NA, "form.childrenRepeat.childrenGroup.treatmentConsent",
NA, NA, NA, NA, "form.childrenRepeat.childrenGroup.noTreatReason",
NA, NA, NA), Type = c(NA, "1", "0", NA, "1", "2", "99", NA, "1",
"2", NA, "1", "2", "3", "99", NA, "1", "2", NA, "1", "2", NA,
"1", "0", "2", "3", NA, "1", "2", "99"), Meaning = c(NA, "Yes",
"No", NA, "No responsible could be found", "They don't want to",
"Other reason", NA, "Male", "Female", NA, "Mother", "Father",
"Neighbor", "Others", NA, "Male", "Female", NA, "Male", "Female",
NA, "Yes", "No", "AMR grappe", "M54 grappe", NA, "allergy", "parent refusal",
"other"), Missing_values = c(NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA), Format_values = c(NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA)), row.names = c(NA, -30L), class = "data.frame")
当前文件如下所示:
variable name type meaning
X1
xxx xxx
xxx xxx
X2
xxx. xxx
xxx xxx
xxx xxx
x3
xxx xxx
我想将其转换为常规数据集,如下所示:
variable name type meaning
x1 xxx. xxx
x1 xxx. xxx
x2 xxx xxx
x2 xxx. xxx
x2 xxx. xxx
x3 xxx. xxx
我的 idea 是:首先按"变量名"分组,然后补上缺失的变量名,最后一步是过滤掉类型和含义列中没有任何值的标题行.但这并不管用.问题是不存在可以为GROUP_BY的变量.
有没有人能帮我想一想怎么才能做到这一点?非常感谢~~!