R für SAS-Anwender:innen
Melinda Higgins, PhD
Research Professor/Senior Biostatistician Emory University

x erstellenx zuweisenx anzeigen[1] zeigt: x hat 1 Elementy als Quadrat von x erstelleny eingebenx <- 4
x
[1] 4
y <- x * x
y
[1] 16
y zuweisenFALSE z zuweiseny und z anzeigeny <- "fish"
z <- FALSE
y
z
[1] "fish"
[1] FALSE
# Drei Zahlen kombinieren
c(5, 3, 2)

# Numerischen Vektor x zuweisen
x <- c(5, 3, 2)
# Ergebnis anzeigen
x
Result
[1] 5 3 2

# Wort child in Zeichenkettenvektor einfügen
y <- c("child")

# Zweites Wort young hinzufügen
y <- c("child", "young")

# Drittes Wort old hinzufügen
y <- c("child", "young", "old")
# y anzeigen
y
Result
[1] "child" "young" "old"

# TRUE in logischen Vektor einfügen
z <- c(TRUE)
TRUETRUE oder FALSEALL CAPS muss verwendet werdenT und F können auch genutzt werden
# FALSE als zweites Element hinzufügen
z <- c(TRUE, FALSE)

# Drittes Element TRUE hinzufügen
z <- c(TRUE, FALSE, TRUE)
# z anzeigen
z
Result
[1] TRUE FALSE TRUE

# Numerischen Vektor a erstellen
a <- c(5.0, 3.1, 2.4)

# Numerischen Vektor a erstellen
a <- c(5.0, 3.1, 2.4)
# Numerischen Vektor b erstellen
b <- c(4.1, 2.2, 5.4)

# m aus a,b mit 3 Zeilen und 2 Spalten erstellen
m <- matrix(c(a, b),
nrow = 3,
ncol = 2)
# m anzeigen
m
[,1] [,2]
[1,] 5.0 4.1
[2,] 3.1 2.2
[3,] 2.4 5.4

# Numerische Variable score erstellen
score <- c(5.0, 3.1, 2.4)
# score anzeigen
score
5.0 3.1 2.4
# Zeichenketten-Variable age erstellen
age <- c("child","young","old")
# age anzeigen
age
"child" "young" "old"
# Logische Variable test erstellen
test <- c(TRUE, FALSE, TRUE)
# test anzeigen
test
TRUE FALSE TRUE
# Zu Data Frame kombinieren
d <- data.frame(score, age, test)
# Data Frame anzeigen
d
score age test
5.0 child TRUE
3.1 young FALSE
2.4 old TRUE

x erstellenclass von x bestimmenstr von x ansehenx <- c(5, 3, 2)
class(x)
[1] "numeric"
str(x)
num [1:3] 5 3 2
y; logischer Vektor zclass von y und z bestimmenstr von y und z ansehenstr(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"
m erstellenm abfragenstr von m ansehenstr(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 d erstellenclass von d abfragenstr von d ansehenstr(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 für SAS-Anwender:innen