setwd("~/Dropbox/Stat R")

Estrutura de dados (objetos) no R (Kobacoff, 2015)

Estruturas de dados no R

a <- c(1, 2, 5, 3, 6, -2, 4)
b <- c("one", "two", "three")
c <- c(TRUE, TRUE, TRUE, FALSE, TRUE, FALSE)

a
b
c


class(a)
class(b)
class(c)

str(a)
str(b)
str(c)
y <- matrix(1:20, nrow=5, ncol=4)
y
class(y)


c <- c(1,26,24,68)
rnames <- c("R1", "R2")
cnames <- c("C1", "C2") 
matriz <- matrix(c, nrow=2, ncol=2, byrow=TRUE,
dimnames=list(rnames, cnames))
 dim1 <- c("A1", "A2")
 dim2 <- c("B1", "B2", "B3")
 dim3 <- c("C1", "C2", "C3", "C4")
 z <- array(1:24, c(2, 3, 4), dimnames=list(dim1, dim2, dim3))
 
 z
class(z)
patientID <- c(1, 2, 3, 4)
age <- c(25, 34, 28, 52)
diabetes <- c("Type1", "Type2", "Type1", "Type1")
status <- c("Poor", "Improved", "Excellent", "Poor")
patientdata <- data.frame(patientID, age, diabetes, status)
patientdata
status <- c("ruim", "bom", "arrazou", "ruim", "muito bom", "arrazou")
status <- factor(status, levels=c("ruim", "bom", "muito bom", "arrazou"))
class(status)
levels(status)

as.numeric(status)
as.character(status)

sex <- factor(sex, levels=c(1, 2), labels=c("Male", "Female"))
g <- "My First List"
h <- c(25, 26, 18, 39)
j <- matrix(1:10, nrow=5)
k <- c("one", "two", "three")
mylist <- list(title=g, ages=h, j, k)
class(mylist)

mylist
names(mylist)

mylist$title
mylist[1]
mylist[[1]]

mylist[[3]][ , 2]

Exercício 2: aprendendo estrutura de dados