What do two commas mean?

At first I have a somewhat embarrassing question. What are commas in R? For example, whenever code like unique[x3,] or something like that does the comma before the bracket do?

Secondly,

 mosaicplot(UCBAdmissions[,,i],) 

What do two commas inside a square bracket mean?

+4
source share
1 answer

The best way to understand these things is to try them yourself and see what they do!

Generally:

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

UCBAdmissions has more than two dimensions, therefore

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

Of course, they can be combined. The UCBAdmissions sample data is a set of six two by two tables:

 dim(UCBAdmissions) # [1] 2 2 6 

Suppose you only need the first row from the first two tables:

 UCBAdmissions[1, , c(1, 2)] # Dept # Gender AB # Male 512 353 # Female 89 17 
+11
source

All Articles