R class of subset of matrix and data.frame

a = matrix(
    c(2, 4, 3, 1, 5, 7), # the data elements
    nrow=2,              # number of rows
    ncol=3,              # number of columns
    byrow = TRUE)        # fill matrix by rows
    
class( (a[1,])
[1] "numeric"

class(a[c(1,2),])
[1] "matrix"

class(as.matrix(a[1,]))
[1] "matrix"
#### a row changed to be a column ????

matrix(a[ 1, ],ncol=3) #
 

  n = c(2, 3, 5)
  s = c("aa", "bb", "cc")
  b = c(TRUE, FALSE, TRUE)
  df = data.frame(n, s, b)


class( df[1,])
[1] "data.frame"

class(df[c(1,2),])
[1] "data.frame"

class(as.matrix(df[1,]))
[1] "matrix"

posted @ 2018-05-25 02:12  emanlee  阅读(173)  评论(0编辑  收藏  举报