Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do two commas mean?

Tags:

syntax

r

First I have a slightly embarrassing question. What do the commas in R represent? For example, whenever there's code that's like unique[x3,] or something similar, What is the comma doing before the bracket?

Second,

mosaicplot(UCBAdmissions[,,i],)

what do the two commas inside the square bracket mean?

like image 368
user2303557 Avatar asked Dec 19 '22 23:12

user2303557


1 Answers

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
like image 94
A5C1D2H2I1M1N2O1R2T1 Avatar answered Jan 15 '23 14:01

A5C1D2H2I1M1N2O1R2T1