如何确定特定的字符串行号

时间:2018-08-20 23:39:26

标签: r

我的数据如下

df<- structure(list(Main = structure(c(5L, 3L, 1L, 2L, 4L, 4L, 2L, 
1L, 5L, 2L, 5L, 4L, 5L, 2L), .Label = c("IsMainbody", "IsMainbodyCandidate", 
"IsMainbodyRejected", "Main", "None"), class = "factor"), Group.IDs = c(52L, 
NA, 2L, 12L, 38L, 38L, 6L, 3L, NA, 49L, 20L, 38L, 54L, 85L), 
    X..Number1 = c(12L, 6L, 1L, 5L, 1L, 1L, 1L, 1L, 17L, 1L, 
    4L, 1L, 1L, 4L), X..No = c(20L, 62L, 2L, 16L, 3L, 3L, 1L, 
    3L, 32L, 3L, 36L, 3L, 1L, 20L), X..Unique.N = c(0L, 0L, 1L, 
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), class = "data.frame", row.names = c(NA, 
-14L))

我正在尝试查找特定字符串的行号。 基于 main 列,我想找到我的样本中有多少个具有“ Main”,多少个具有“ IsmainbodyCandidate”和多少个“ IsMainbodyRejected”

然后,我想制作一个仅由 Main Ismainbody Ismainbodycandidates 组成的新数据集,如下所示。

Main       Group IDs    # Number1   # No    # Unique N
IsMainbody.     2        1         2           1
IsMainbodyCandidate 12   5        16           0
Main           38        1        3            0
Main           38        1        3             0
IsMainbodyCandidate 6    1        1            0
IsMainbody  3            1        3           0
IsMainbodyCandidate 49   1        3           0
IsMainbodyCandidate 85   4       20            0

1 个答案:

答案 0 :(得分:1)

cloneDeep