我有这个数据框:
percentDf <- data.frame(category=c("a", "a", "b", "c", "c", "d"),
percent=c(50, 50, 100, 30, 70, 100))
percentDf
category percent
1 a 50
2 a 50
3 b 100
4 c 30
5 c 70
6 d 100
在值为percent
100 的行中,我需要复制该行,并将其添加到下面。这应该是输出的数据帧:
percentDfComplete <- data.frame(category=c("a", "a", "b", "b", "c", "c", "d", "d"),
percent=c(50, 50, 100, 100, 30, 70, 100, 100))
percentDfComplete
category percent
1 a 50
2 a 50
3 b 100
4 b 100
5 c 30
6 c 70
7 d 100
8 d 100
做这个的最好方式是什么?