Remove First Row of DataFrame in R
Last Updated :
23 Aug, 2021
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
data= data.frame (names= c ( "sravan" , "boby" , "ojaswi" , "gnanesh" ,
"rohith" ),id= c (1,2,3,4,5))
data
data=data[- 1, ]
print ( "------" )
data
|
Output:
Example 2: R program to create dataframe with 4 columns and delete the first row
R
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" ))
data
data = data[- 1, ]
print ( "------" )
data
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...