Back
I have a data frame named "mydata" that looks like this
A B C D 1. 5 4 4 4 2. 5 4 4 4 3. 5 4 4 4 4. 5 4 4 4 5. 5 4 4 4 6. 5 4 4 4 7. 5 4 4 4
A B C D
1. 5 4 4 4
2. 5 4 4 4
3. 5 4 4 4
4. 5 4 4 4
5. 5 4 4 4
6. 5 4 4 4
7. 5 4 4 4
I'd like to delete row 2,4,6. For example, like this:
A B C D1. 5 4 4 4 3. 5 4 4 4 5. 5 4 4 4 7. 5 4 4 4
To delete rows in a data frame we use the (-) operator along with the row names and assign it to our data frame.
In your case:
myData <- data.frame(A= rep(5,7), B= rep(4,7), C= rep(4,7), D = rep(4,7))myData <- myData[-c(2,4,6),]myData
myData <- data.frame(A= rep(5,7),
B= rep(4,7),
C= rep(4,7),
D = rep(4,7))
myData <- myData[-c(2,4,6),]
myData
A B C D1 5 4 4 43 5 4 4 45 5 4 4 47 5 4 4 4
Note: Make sure that you add a comma after the row numbers to include all columns.
31k questions
32.8k answers
501 comments
693 users