R untuk Pengguna SAS
Melinda Higgins, PhD
Research Professor/Senior Biostatistician Emory University

xxx[1] menandakan x punya 1 elemeny sebagai kuadrat xyx <- 4
x
[1] 4
y <- x * x
y
[1] 16
yFALSE ke zy dan zy <- "fish"
z <- FALSE
y
z
[1] "fish"
[1] FALSE
# Gabungkan tiga angka
c(5, 3, 2)

# Tetapkan vektor numerik ke x
x <- c(5, 3, 2)
# Lihat hasil
x
Hasil
[1] 5 3 2

# Tambah kata child ke vektor karakter
y <- c("child")

# Tambah kata kedua young
y <- c("child", "young")

# Tambah kata ketiga old
y <- c("child", "young", "old")
# Lihat y
y
Hasil
[1] "child" "young" "old"

# Tambah TRUE ke vektor logika
z <- c(TRUE)
TRUETRUE atau FALSEALL CAPST dan F juga bisa
# Tambah FALSE sebagai elemen kedua
z <- c(TRUE, FALSE)

# Tambah elemen ketiga TRUE
z <- c(TRUE, FALSE, TRUE)
# Lihat z
z
Hasil
[1] TRUE FALSE TRUE

# Buat vektor numerik a
a <- c(5.0, 3.1, 2.4)

# Buat vektor numerik a
a <- c(5.0, 3.1, 2.4)
# Buat vektor numerik b
b <- c(4.1, 2.2, 5.4)

# Buat m dari a,b dengan 3 baris 2 kolom
m <- matrix(c(a, b),
nrow = 3,
ncol = 2)
# Lihat m
m
[,1] [,2]
[1,] 5.0 4.1
[2,] 3.1 2.2
[3,] 2.4 5.4

# Buat variabel numerik score
score <- c(5.0, 3.1, 2.4)
# Lihat score
score
5.0 3.1 2.4
# Buat variabel karakter age
age <- c("child","young","old")
# Lihat age
age
"child" "young" "old"
# Buat variabel logika test
test <- c(TRUE, FALSE, TRUE)
# Lihat test
test
TRUE FALSE TRUE
# Gabungkan untuk membuat data frame
d <- data.frame(score, age, test)
# Lihat data frame
d
score age test
5.0 child TRUE
3.1 young FALSE
2.4 old TRUE

xclass dari xstr dari xx <- c(5, 3, 2)
class(x)
[1] "numeric"
str(x)
num [1:3] 5 3 2
y; vektor logika zclass dari y dan zstr dari y dan 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"
mmstr 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 dari dstr dari 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 untuk Pengguna SAS