CALCULADORA
20-10
## [1] 10
seq(2.5,10.5,2)
## [1] 2.5 4.5 6.5 8.5 10.5
getwd()
## [1] "C:/Users/admin/Documents/Maripaz Barboza; universidad/Métodos de analisis"
x<-1.5
y<--3.5
paste("El punto es (",x,",",y,")", sep="")
## [1] "El punto es (1.5,-3.5)"
a<- "Esto es un ejemplo"
substr(a,6,11)
## [1] "es un "
x= c(2,4,5,7,10)
mean(x)
## [1] 5.6
matrix <- matrix (3:32, nrow=6, ncol=5)
matrix
## [,1] [,2] [,3] [,4] [,5]
## [1,] 3 9 15 21 27
## [2,] 4 10 16 22 28
## [3,] 5 11 17 23 29
## [4,] 6 12 18 24 30
## [5,] 7 13 19 25 31
## [6,] 8 14 20 26 32
str(matrix)
## int [1:6, 1:5] 3 4 5 6 7 8 9 10 11 12 ...
cells = c(1.2,26,24,68)
names = c("F1", "F2")
namesc = c("C1", "C2")
matrix2 <- matrix(cells, nrow=2, ncol=2, byrow=TRUE,dimnames=list(names, namesc))
matrix2
## C1 C2
## F1 1.2 26
## F2 24.0 68
Data frames
size <- c(173,176,180,165,185,175,186,160,160,172,177,175,176)
age <- c(23,24,20,22,23,24,25,28,21,21,31,24,26)
sex <- c(1,1,0,1,1,1,1,0,1,1,0,1,1)
str(sex) #estructura de la variable
## num [1:13] 1 1 0 1 1 1 1 0 1 1 ...
is.numeric(sex)
## [1] TRUE
is.factor(sex)
## [1] FALSE
sex <- as.factor(sex)
str(sex)
## Factor w/ 2 levels "0","1": 2 2 1 2 2 2 2 1 2 2 ...
gl(4,2)
## [1] 1 1 2 2 3 3 4 4
## Levels: 1 2 3 4
data <- data.frame(size,sex,age)
data
## size sex age
## 1 173 1 23
## 2 176 1 24
## 3 180 0 20
## 4 165 1 22
## 5 185 1 23
## 6 175 1 24
## 7 186 1 25
## 8 160 0 28
## 9 160 1 21
## 10 172 1 21
## 11 177 0 31
## 12 175 1 24
## 13 176 1 26
data
## size sex age
## 1 173 1 23
## 2 176 1 24
## 3 180 0 20
## 4 165 1 22
## 5 185 1 23
## 6 175 1 24
## 7 186 1 25
## 8 160 0 28
## 9 160 1 21
## 10 172 1 21
## 11 177 0 31
## 12 175 1 24
## 13 176 1 26
head(data)
## size sex age
## 1 173 1 23
## 2 176 1 24
## 3 180 0 20
## 4 165 1 22
## 5 185 1 23
## 6 175 1 24
tail(data)
## size sex age
## 8 160 0 28
## 9 160 1 21
## 10 172 1 21
## 11 177 0 31
## 12 175 1 24
## 13 176 1 26
str(data)
## 'data.frame': 13 obs. of 3 variables:
## $ size: num 173 176 180 165 185 175 186 160 160 172 ...
## $ sex : Factor w/ 2 levels "0","1": 2 2 1 2 2 2 2 1 2 2 ...
## $ age : num 23 24 20 22 23 24 25 28 21 21 ...
is.data.frame(data)
## [1] TRUE
dim(data) #estructura de filas y columnas
## [1] 13 3
colnames(data) #cuales son las colunmas
## [1] "size" "sex" "age"
summary (data) #datos estadisticos
## size sex age
## Min. :160.0 0: 3 Min. :20
## 1st Qu.:172.0 1:10 1st Qu.:22
## Median :175.0 Median :24
## Mean :173.8 Mean :24
## 3rd Qu.:177.0 3rd Qu.:25
## Max. :186.0 Max. :31
read.table("jugadores.txt")
## V1 V2 V3
## 1 lateral edad estatura
## 2 1 27 178,56
## 3 1 22 181,5
## 4 2 23 183
## 5 1 24 162
## 6 2 26 172
## 7 1 26 171,5
## 8 1 33 160
## 9 1 26 163
## 10 1 29 167
## 11 1 24 161,2
## 12 2 25 170
## 13 2 26 187
## 14 1 23 166
## 15 1 27 162
## 16 2 25 194
## 17 1 24 160
## 18 2 22 185
## 19 1 21 155
## 20 1 21 175
## 21 2 22 183
## 22 1 22 167
## 23 1 30 172
## 24 1 25 163
## 25 1 24 172
## 26 1 23 161
## 27 2 33 182
data<-read.table("jugadores.txt")
head(data)
## V1 V2 V3
## 1 lateral edad estatura
## 2 1 27 178,56
## 3 1 22 181,5
## 4 2 23 183
## 5 1 24 162
## 6 2 26 172
str(data)
## 'data.frame': 27 obs. of 3 variables:
## $ V1: chr "lateral" "1" "1" "2" ...
## $ V2: chr "edad" "27" "22" "23" ...
## $ V3: chr "estatura" "178,56" "181,5" "183" ...
data<-read.table("jugadores.txt",head=T,dec=",")
head(data)
## lateral edad estatura
## 1 1 27 178.56
## 2 1 22 181.50
## 3 2 23 183.00
## 4 1 24 162.00
## 5 2 26 172.00
## 6 1 26 171.50
data$estatura + 10
## [1] 188.56 191.50 193.00 172.00 182.00 181.50 170.00 173.00 177.00 171.20
## [11] 180.00 197.00 176.00 172.00 204.00 170.00 195.00 165.00 185.00 193.00
## [21] 177.00 182.00 173.00 182.00 171.00 192.00
tower <- read.csv("Fluxtower.csv",head=T,dec=".")
View(tower)
tower <- read.table("Fluxtower.csv",head=T,dec=".",sep=",")
View(tower)
Subset de datos
player <- read.table("jugadores.txt",head=T,dec=".")
View(player)
player2 <- player[,1:2]
View(player2)
playerder <- subset(player, lateral == "2")
playerder
## lateral edad estatura
## 3 2 23 183
## 5 2 26 172
## 11 2 25 170
## 12 2 26 187
## 15 2 25 194
## 17 2 22 185
## 20 2 22 183
## 26 2 33 182