Suppose we want to access data from a data frame by row. The examples are simplified but when ordering a data frame by row names, for example, (df[order(row.names(df)]
) we use the same technique.
If the data frame has one column, we get back an atomic vector:
> df
x1
a x
b y
c z
> df[1, ] # returns atomic vector
[1] x
If the data frame has two columns, we get back a 1-row data frame including the row name:
> df
x1 x2
a x u
b y v
c z w
> df[1, ] # returns data frame
X1 X2
a x u
I don't understand why the same operation on the data frame yields two types of results depending on how many columns the frame has.