Remove First Row of DataFrame in R
In this article, we are going to see how to remove the first row from the dataframe. We can remove first row by indexing the dataframe.
Syntax:
data[-1,]
where -1 is used to remove the first row which is in row position
Example 1: R program to create a dataframe with 2 columns and delete the first row
R
# create dataframe with names and id data= data.frame (names= c ( "sravan" , "boby" , "ojaswi" , "gnanesh" , "rohith" ),id= c (1,2,3,4,5)) # display data # remove first row data=data[- 1, ] print ( "------" ) # display data |
Output:
Example 2: R program to create dataframe with 4 columns and delete the first row
R
# create dataframe with names ,id,phone and address data = data.frame (names= c ( "sravan" , "boby" , "ojaswi" , "gnanesh" , "rohith" ), id= c (1, 2, 3, 4, 5), phone= c ( "91834567450" , "2222222222" , "333333333333" , "5555555555555" , "333333333333" ), address= c ( "hyd" , "kol" , "patna" , "bikat" , "guntut" )) # display data # remove first row data = data[- 1, ] print ( "------" ) # display data |
Output:
Contact Us