Categories
status

Differences in single argument subscript …

Differences in single argument subscripting in matrix and data frame.
Even though the two variables look similar, the results are different depending on the data type.
The single argument scripting of data frame returns a column, while matrix returns an element according to its position as matrix is a vector.

> class(my2)
[1] "data.frame"
> my2
  a1  b  c a1.1
1 10 20 30   35
2 10 20 30   35
> my2[1]
  a1
1 10
2 10
> class(my2.matrix)
[1] "matrix"
> my2.matrix
  a1  b  c a1.1
1 10 20 30   35
1 10 20 30   35
> my2.matrix[1]
[1] 10 
Categories
status

Subscripting in R * [ gives the same …

Subscripting in R

[ gives the same data type as the data it is applied to.
[[ and $ extract the element and the data type is not necessarily the same as that of the data it is applied to.

$ does partial matching.
[ and [[ don’t.

$ does not evaluate.
[ and [[ evaluate their arguments.