The key idea is you form a set of the rows you want to remove, and keep the complement of that set.
(关键思想是形成要删除的行的集合,并保留该集合的补充。)
In R, the complement of a set is given by the '-' operator.
(在R中,集合的补码由'-'运算符给出。)
So, assuming the data.frame
is called myData
:
(因此,假设data.frame
称为myData
:)
myData[-c(2, 4, 6), ] # notice the -
Of course, don't forget to "reassign" myData
if you wanted to drop those rows entirely---otherwise, R just prints the results.
(当然,如果您想完全删除那些行,请不要忘记“重新分配” myData
否则,R只会打印结果。)
myData <- myData[-c(2, 4, 6), ]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…