I have a data table with 5778 rows and 28 columns. How do I delete ALL of the 1st row. E.g. let's say the data table had 3 rows and 4 columns and looked like this:
Row number tracking_id 3D71 3D72 3D73
1 xxx 1 1 1
2 yyy 2 2 2
3 zzz 3 3 3
I want to create a data table that looks like this:
Row number tracking_id 3D71 3D72 3D73
1 yyy 2 2 2
2 zzz 3 3 3
i.e. I want to delete all of row number 1 and then shift the other rows up.
I have tried datatablename[-c(1)]
but this deletes the first column not the first row!
Many thanks for any help!
R provides a subset() function to delete or drop a single row and multiple rows from the DataFrame (data. frame), you can also use the notation [] and -c().
To remove all rows having NA, we can use na. omit function. For Example, if we have a data frame called df that contains some NA values then we can remove all rows that contains at least one NA by using the command na. omit(df).
To remove the row(s) and column(s) of a current matrix in R, we use the c() function.
You can do this via
dataframename = dataframename[-1,]
It can be easily done with indexing the data.table/data frame as mentioned by @joni. You can also do with
datatablename <- datatablename[2:nrow(datatablename), ]
You can find more interesting stuff about data.table here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With