How to prevent a data frame degrading to a vector

Post date: Apr 2, 2014 8:26:44 AM

Normally a dataframe is supposed to have more than 1 column. By default when n-1 columns are dropped from an n-column data frame, the remaining 1 column will be automatically degraded to a vector. To prevent such degradation, use 'drop=F' when subsetting the data frame. For example:

> df   a b  c 1 1 5  9 2 2 6 10 3 3 7 11 4 4 8 12   > df[,2] [1] 5 6 7 8   > df[,2,drop=F]   b 1 5 2 6 3 7 4 8
Created by Pretty R at inside-R.org

---------