4

首先我有一个有点尴尬的问题。R中的逗号代表什么?例如,只要有类似unique[x3,]或类似的代码,括号前的逗号在做什么?

第二,

mosaicplot(UCBAdmissions[,,i],)

方括号内的两个逗号是什么意思?

4

1 回答 1

11

The best way to understand these things is to try them out on your own and see what they do!

In general:

mydf[1, ] ## Get the first row
mydf[, 3] ## Get the third column

The UCBAdmissions has more than two dimensions, so

UCBAdmissions[, , 1] ## Get the first table in the 3D array

Of course, these can be combined. The UCBAdmissions sample data is a set of 6 two-by-two table:

dim(UCBAdmissions)
# [1] 2 2 6

Let's imagine you wanted the first row from just the first two tables:

UCBAdmissions[1, , c(1, 2)]
#         Dept
# Gender     A   B
#   Male   512 353
#   Female  89  17
于 2013-09-22T06:05:19.463 回答