【发布时间】:2021-10-17 00:42:57
【问题描述】:
我使用separate()函数拆分列:Enterdateofexam2,它是字符格式,值如“25.07”,“13.09”,“16.06”...我的目标是将它拆分为日(25)和月(07),然后使用 convert = true 将它们转换为数字进行下一步过滤。
我的代码是:
jimma3n <- jimma3 %>%
select(Enterdateofexam2, Enterdayofexam, UniqueKey,MEDICALRECORD)%>%
separate(Enterdateofexam2,into=c("day", "month"), sep=".", convert = TRUE)
view (jimma3n)
但 R 一直在警告我:
Expected 2 pieces. Additional pieces discarded in 4088 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
那么任何人都可以帮助找出我的代码的哪一部分有问题吗?谢谢~~!
【问题讨论】:
-
可以发一下
dput(head(data))吗? -
我运行它,它显示:structure(list(Enterdateofexam2 = list(c("", "7.06"), c("", "8.06"), c("", "9.06 "), c("", "2.12"), c("", "3.12"), c("", "4.12")), Enterdayofexam = c("1", "2", "3", "1", "2", "3"), UniqueKey = c("530", "530", "530", "531", "531", "531"), MEDICALRECORD = c("577207", “577207”、“577207”、“575333”、“575333”、“575333”)),row.names = c(NA,-6L),class= c(“tbl_df”,“tbl”,“data.frame ")),为什么数字前面有("",...),如何去掉"",只保留列中的值?非常感谢。
-
这是因为您的
Enterdateofexam2已作为列表加载到您的data.frame中,这就是您收到错误的原因!