HW-Scientist
HW-Scientist

Reputation: 434

How to delete a row named (not set)

I have a data set with 200 rows, one of which is named "(not set)". And I want to delete this particular row. Is there any method if I don't want to delete it by using the row number, such as dat1[-c(1, 2, 3),]? Thank you very much if anyone could help.

Upvotes: 0

Views: 36

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521194

Assuming you have a data frame with set row names, then there is a simple way to exclude one or more rows using the row names:

df <- data.frame(v1=c(1:3), v2=c(4:6), v3=c(7:9))
row.names(df) <- c("one", "(not set)", "three")
df
         v1 v2 v3
one       1  4  7
(not set) 2  5  8
three     3  6  9

df <- df[row.names(df) != "(not set)", ]
df
      v1 v2 v3
one    1  4  7
three  3  6  9

Upvotes: 2

Related Questions