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"
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步