A data frame is no longer a data frame after an item has been deleted

I have a simple data frame like

myframe<-data.frame(c(NA, NA,NA, 1,2,3,4,5,NA,7,8,9)) 

I delete the first element as follows:

 myframe<-myframe[-1,] 

And when I do this:

 is.data.frame(myframe) 

The result is:

 [1] FALSE 

I can fix this:

 myframe<-data.frame(myframe[-1,]) 

but I thought that the data frame will not cease to be a data frame after deleting elements

What's going on here? I code all day, and my brain is fried, and I can't figure it out. Please, help.

My goal is to remove only the first n inputs of NA in the data frame. If they meet somewhere in the middle, it does not matter.

Thanks!

+5
source share
1 answer

Since you only have one column, R will automatically convert the result to a vector. If you want to maintain the structure of the data frame, you can enter

 myframe[-1, , drop = FALSE] 
+9
source

All Articles