nsub | R Documentation |
Function to compute the number of subjects.
nsub(id, data)
id |
vector to specify a subject id variable. |
data |
optional data frame that contains the variable specified above. |
The function simply computes the number of subjects in a long-format dataset (i.e., the number of unique values of the id variable).
A scalar.
Wolfgang Viechtbauer wvb@wvbauer.com
# illustrative dataset
dat <- data.frame(subj=rep(1:4, each=5),
obs = 1:5,
age = rep(c(20,31,27,22), each=5),
stress = c(2,3,NA,4,2, 3,3,NA,3,NA, 1,1,2,6,4, 1,2,1,3,1))
dat
# compute the number of subjects
nsub(subj, dat)
# or specify the subject variable this way
nsub(dat$subj)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.