I want to "subset" this dataframe and remove the second row using the rowname
myDataFrame <- as.data.frame(rnorm(5))
rownames(MyDataFrame)
#"1" "2" "3" "4" "5"
myDataFrame[-2,]
# 0.2706859 0.9708845 0.7559821 -0.2063368
I want to be able to get the results above, but in a data frame form (with the original row names). I looked around and it seems the way to select by rowname is to use the which function, but I'm not sure how it would work in this context.
You can add an argument drop = FALSE.
> mydf[-2, , drop = FALSE]
rnorm(5)
1 1.9602780
3 0.1078827
4 -0.8517422
5 -0.8300695
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