How to delete rows from Data Frame in R

There is no direct method to remove rows from R. We can remove the row(s) from Data Frame by creating new Data Frame.

How to delete rows from Data Frame in R?

df< -data.frame(A=1:8, B=3:10, C=5:12, D=7:14) #Create Data Frame > df #Data of Data Frame. A B C D 1 1 3 5 7 2 2 4 6 8 3 3 5 7 9 4 4 6 8 10 5 5 7 9 11 6 6 8 10 12 7 7 9 11 13 8 8 10 12 14

Delete 3rd,6th, and 7th rows from Data Frame.

df1< -df[-c(3,6,7),] # Remove the 3rd, 6th and 7the elements and assign to new Data Frame. > df1 A B C D 1 1 3 5 7 2 2 4 6 8 4 4 6 8 10 5 5 7 9 11 8 8 10 12 14

Now assign df1 Data Frame to df Data Frame.

> df< -df1 > df A B C D #3rd, 6th and 7th rows deleted from original data frame. 1 1 3 5 7 2 2 4 6 8 4 4 6 8 10 5 5 7 9 11 8 8 10 12 14

CheapSexCams
Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by k2schools
%d bloggers like this: