I have a simple data frame as
myframe<-data.frame(c(NA, NA,NA, 1,2,3,4,5,NA,7,8,9))
I remove the first element like so:
myframe<-myframe[-1,]
And when I do this:
is.data.frame(myframe)
The result I get is:
[1] FALSE
I can fix it by:
myframe<-data.frame(myframe[-1,])
but I thought that the data frame wouldn't stop being a data frame after removing elements
What's happening here? I've been coding all day and my brain is fried and I cannot figure this out. Please help.
My objective is to only remove the first n occurences of NAs in a data frame. If they occur somewhere in the middle, it doesn't matter.
Thank you!
Because you only have one column, R automatically converts the result to a vector. If you want to preserve the data frame structure you can type
myframe[-1, , drop = FALSE]
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