I'm totally confused ! I have a one column dataframe in R :
temp1 = structure(list(Hamburg = c("Hamburg", "4562", "4604")), class = "data.frame", row.names = c(NA,
-3L))
str(temp1)
'data.frame': 3 obs. of 1 variable:
$ Hamburg: chr "Hamburg" "4562" "4604"
When I remove the first row by :
temp1 = temp1[-1,]
then the remaining is not a dataframe any more ! and I do not have the column name as well !
temp1
[1] "4562" "4604"
str(temp1)
chr [1:2] "4562" "4604"
How could I fix it ? I would like to keep the dataframe structure just get rid of the first row !
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 rows with an in R we can use the na. omit() and <code>drop_na()</code> (tidyr) functions. For example, na.
You cannot actually delete a row, but you can access a data frame without some rows specified by negative index. This process is also called subsetting in R language. A Big Note: You should provide a comma after the negative index vector -c().
temp1 = temp1[-1,, drop=F]
str(temp1)
'data.frame': 2 obs. of 1 variable:
$ Hamburg: chr "4562" "4604"
The default is T, which reduces the data.frame to its smallest dimension How do I extract a single column from a data.frame as a data.frame?
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