此问题已在此处有答案:
Remove all rows where length of string is more than n(4个答案)
13小时前关闭
我们在“标识符”列中有值,其值范围为7-11个字符/数字。是否有方法删除值超过9个字符的行?
Identifier X1 X2 X3 X4
2021047.PR 0 0 1 9
2021047.YB 3 0 3 0
2021047.C 0 5 0 3
2020048 8 6 2 0
2021049.Arv 7 0 3 0
2021049.BR 0 3 0 8
2021049.C 3 0 0 1
2021050 4 0 7 0
预期结果:首选Dplyr/Tidy结果
Identifier X1 X2 X3 X4
2021047.C 0 5 0 3
2020048 8 6 2 0
2021049.C 3 0 0 1
2021050 4 0 7 0
structure(list(Identifier = c("2021047.PR", "2021047.YB", "2021047.C",
"2020048", "2021049.Arv", "2021049.BR", "2021049.C", "2021050"
), X1 = c(0L, 3L, 0L, 8L, 7L, 0L, 3L, 4L), X2 = c(0L, 0L, 5L,
6L, 0L, 3L, 0L, 0L), X3 = c(1L, 3L, 0L, 2L, 3L, 0L, 0L, 7L),
X4 = c(9L, 0L, 3L, 0L, 0L, 8L, 1L, 0L)), class = "data.frame", row.names = c(NA,
-8L))
1条答案
按热度按时间nmpmafwu1#
使用
nchar
获取字符串的长度