R voor SAS-gebruikers
Melinda Higgins, PhD
Research Professor/Senior Biostatistician Emory University

xxx[1] betekent dat x 1 element heefty als het kwadraat van xyx <- 4
x
[1] 4
y <- x * x
y
[1] 16
yFALSE toe aan zy en zy <- "fish"
z <- FALSE
y
z
[1] "fish"
[1] FALSE
# Combineer drie getallen
c(5, 3, 2)

# Ken numerieke vector toe aan x
x <- c(5, 3, 2)
# Bekijk resultaat
x
Resultaat
[1] 5 3 2

# Voeg woord child toe aan karaktervector
y <- c("child")

# Voeg tweede woord young toe
y <- c("child", "young")

# Voeg derde woord old toe
y <- c("child", "young", "old")
# Bekijk y
y
Resultaat
[1] "child" "young" "old"

# Voeg TRUE toe aan logische vector
z <- c(TRUE)
TRUETRUE of FALSEALL CAPS is vereistT en F kunnen ook
# Voeg FALSE toe als tweede element
z <- c(TRUE, FALSE)

# Voeg derde element TRUE toe
z <- c(TRUE, FALSE, TRUE)
# Bekijk z
z
Resultaat
[1] TRUE FALSE TRUE

# Maak numerieke vector a
a <- c(5.0, 3.1, 2.4)

# Maak numerieke vector a
a <- c(5.0, 3.1, 2.4)
# Maak numerieke vector b
b <- c(4.1, 2.2, 5.4)

# Maak m van a,b met 3 rijen 2 kolommen
m <- matrix(c(a, b),
nrow = 3,
ncol = 2)
# Bekijk m
m
[,1] [,2]
[1,] 5.0 4.1
[2,] 3.1 2.2
[3,] 2.4 5.4

# Maak numerieke variabele score
score <- c(5.0, 3.1, 2.4)
# Bekijk score
score
5.0 3.1 2.4
# Maak karaktervariabele age
age <- c("child","young","old")
# Bekijk age
age
"child" "young" "old"
# Maak logische variabele test
test <- c(TRUE, FALSE, TRUE)
# Bekijk test
test
TRUE FALSE TRUE
# Combineer tot data frame
d <- data.frame(score, age, test)
# Bekijk data frame
d
score age test
5.0 child TRUE
3.1 young FALSE
2.4 old TRUE

xclass van xstr van xx <- c(5, 3, 2)
class(x)
[1] "numeric"
str(x)
num [1:3] 5 3 2
y; logische vector zclass van y en zstr van y en zstr(y)
chr [1:3] "child" "young" "old"
str(z)
logi [1:3] TRUE FALSE TRUE
y <- c("child","young","old")
z <- c(TRUE, FALSE, TRUE)
class(y)
[1] "character"
class(z)
[1] "logical"
mm opstr van mstr(m)
num [1:3, 1:2] 5 3.1 2.4 4.1 2.2 5.4
a <- c(5.0, 3.1, 2.4)
b <- c(4.1, 2.2, 5.4)
m <- matrix(c(a, b),
nrow = 3,
ncol = 2)
class(m)
[1] "matrix"
data.frame dclass van d opstr van dstr(d)
'data.frame': 3 obs. of 3 variables:
$ score: num 5 3.1 2.4
$ age : Factor w/ 3 levels
"child","old",..: 1 3 2
$ test : logi TRUE FALSE TRUE
score <- c(5.0, 3.1, 2.4)
age <- c("child","young","old")
test <- c(TRUE, FALSE, TRUE)
d <- data.frame(score, age, test)
class(d)
[1] "data.frame"
R voor SAS-gebruikers