edades <-c(50,34,45,35,38,36,29,43,40,28,28,
30,28,45,40,39,28,32,45,35)
nombres <- c("Rubén","Dany","Alma","Carlos","Daniel","Dell","Francisco","Isaac",
"Javier","Jesus","Laura","Luis","Maria","Verenice","Gabriel","Jeorgina","Claudia","Adriana","Javier","Ernesto")
generos <- c('M','F','F','M','M','M','M','M','M','M','F','M','F','F','M','F',
'F','F','M','M')
profesiones <-rep(c("Informatica","Sistemas","Civil","Administracion","Arquitectura"),4)
deporte <-rep(c(TRUE,FALSE),10)
*visualizar cada vector
nombres
## [1] "Rubén" "Dany" "Alma" "Carlos" "Daniel" "Dell"
## [7] "Francisco" "Isaac" "Javier" "Jesus" "Laura" "Luis"
## [13] "Maria" "Verenice" "Gabriel" "Jeorgina" "Claudia" "Adriana"
## [19] "Javier" "Ernesto"
edades
## [1] 50 34 45 35 38 36 29 43 40 28 28 30 28 45 40 39 28 32 45 35
generos
## [1] "M" "F" "F" "M" "M" "M" "M" "M" "M" "M" "F" "M" "F" "F" "M" "F" "F" "F" "M"
## [20] "M"
profesiones
## [1] "Informatica" "Sistemas" "Civil" "Administracion"
## [5] "Arquitectura" "Informatica" "Sistemas" "Civil"
## [9] "Administracion" "Arquitectura" "Informatica" "Sistemas"
## [13] "Civil" "Administracion" "Arquitectura" "Informatica"
## [17] "Sistemas" "Civil" "Administracion" "Arquitectura"
deporte
## [1] TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE
## [13] TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE
datos <-data.frame(nombres, edades, generos, profesiones, deporte)
datos
## nombres edades generos profesiones deporte
## 1 Rubén 50 M Informatica TRUE
## 2 Dany 34 F Sistemas FALSE
## 3 Alma 45 F Civil TRUE
## 4 Carlos 35 M Administracion FALSE
## 5 Daniel 38 M Arquitectura TRUE
## 6 Dell 36 M Informatica FALSE
## 7 Francisco 29 M Sistemas TRUE
## 8 Isaac 43 M Civil FALSE
## 9 Javier 40 M Administracion TRUE
## 10 Jesus 28 M Arquitectura FALSE
## 11 Laura 28 F Informatica TRUE
## 12 Luis 30 M Sistemas FALSE
## 13 Maria 28 F Civil TRUE
## 14 Verenice 45 F Administracion FALSE
## 15 Gabriel 40 M Arquitectura TRUE
## 16 Jeorgina 39 F Informatica FALSE
## 17 Claudia 28 F Sistemas TRUE
## 18 Adriana 32 F Civil FALSE
## 19 Javier 45 M Administracion TRUE
## 20 Ernesto 35 M Arquitectura FALSE
datos$nombres
## [1] Rubén Dany Alma Carlos Daniel Dell Francisco
## [8] Isaac Javier Jesus Laura Luis Maria Verenice
## [15] Gabriel Jeorgina Claudia Adriana Javier Ernesto
## 19 Levels: Adriana Alma Carlos Claudia Daniel Dany Dell Ernesto ... Verenice
datos$deporte
## [1] TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE
## [13] TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE
datos
## nombres edades generos profesiones deporte
## 1 Rubén 50 M Informatica TRUE
## 2 Dany 34 F Sistemas FALSE
## 3 Alma 45 F Civil TRUE
## 4 Carlos 35 M Administracion FALSE
## 5 Daniel 38 M Arquitectura TRUE
## 6 Dell 36 M Informatica FALSE
## 7 Francisco 29 M Sistemas TRUE
## 8 Isaac 43 M Civil FALSE
## 9 Javier 40 M Administracion TRUE
## 10 Jesus 28 M Arquitectura FALSE
## 11 Laura 28 F Informatica TRUE
## 12 Luis 30 M Sistemas FALSE
## 13 Maria 28 F Civil TRUE
## 14 Verenice 45 F Administracion FALSE
## 15 Gabriel 40 M Arquitectura TRUE
## 16 Jeorgina 39 F Informatica FALSE
## 17 Claudia 28 F Sistemas TRUE
## 18 Adriana 32 F Civil FALSE
## 19 Javier 45 M Administracion TRUE
## 20 Ernesto 35 M Arquitectura FALSE
datos[3, ] # Todas las columnas
## nombres edades generos profesiones deporte
## 3 Alma 45 F Civil TRUE
datos[5, c(1,4)] # columna 1 y 4 del renglon 5
## nombres profesiones
## 5 Daniel Arquitectura
datos[-5, -5]
## nombres edades generos profesiones
## 1 Rubén 50 M Informatica
## 2 Dany 34 F Sistemas
## 3 Alma 45 F Civil
## 4 Carlos 35 M Administracion
## 6 Dell 36 M Informatica
## 7 Francisco 29 M Sistemas
## 8 Isaac 43 M Civil
## 9 Javier 40 M Administracion
## 10 Jesus 28 M Arquitectura
## 11 Laura 28 F Informatica
## 12 Luis 30 M Sistemas
## 13 Maria 28 F Civil
## 14 Verenice 45 F Administracion
## 15 Gabriel 40 M Arquitectura
## 16 Jeorgina 39 F Informatica
## 17 Claudia 28 F Sistemas
## 18 Adriana 32 F Civil
## 19 Javier 45 M Administracion
## 20 Ernesto 35 M Arquitectura
datos[,"nombres"]
## [1] Rubén Dany Alma Carlos Daniel Dell Francisco
## [8] Isaac Javier Jesus Laura Luis Maria Verenice
## [15] Gabriel Jeorgina Claudia Adriana Javier Ernesto
## 19 Levels: Adriana Alma Carlos Claudia Daniel Dany Dell Ernesto ... Verenice
losquehacendeporte <- subset(datos, deporte==TRUE)
losquehacendeporte
## nombres edades generos profesiones deporte
## 1 Rubén 50 M Informatica TRUE
## 3 Alma 45 F Civil TRUE
## 5 Daniel 38 M Arquitectura TRUE
## 7 Francisco 29 M Sistemas TRUE
## 9 Javier 40 M Administracion TRUE
## 11 Laura 28 F Informatica TRUE
## 13 Maria 28 F Civil TRUE
## 15 Gabriel 40 M Arquitectura TRUE
## 17 Claudia 28 F Sistemas TRUE
## 19 Javier 45 M Administracion TRUE
lasmujeres <- subset(datos, generos=='F')
lasmujeres
## nombres edades generos profesiones deporte
## 2 Dany 34 F Sistemas FALSE
## 3 Alma 45 F Civil TRUE
## 11 Laura 28 F Informatica TRUE
## 13 Maria 28 F Civil TRUE
## 14 Verenice 45 F Administracion FALSE
## 16 Jeorgina 39 F Informatica FALSE
## 17 Claudia 28 F Sistemas TRUE
## 18 Adriana 32 F Civil FALSE
muj.depor.sist <- subset(datos, generos=='F' & deporte==TRUE & profesiones=='Sistemas')
muj.depor.sist
## nombres edades generos profesiones deporte
## 17 Claudia 28 F Sistemas TRUE
n <- nrow(datos)
n
## [1] 20
ncols <- ncol(datos)
ncols
## [1] 5
names(datos)
## [1] "nombres" "edades" "generos" "profesiones" "deporte"
otrosdatos <- datos
colnames(otrosdatos) <- c("nom",'eda','gen','pro','dep')
otrosdatos
## nom eda gen pro dep
## 1 Rubén 50 M Informatica TRUE
## 2 Dany 34 F Sistemas FALSE
## 3 Alma 45 F Civil TRUE
## 4 Carlos 35 M Administracion FALSE
## 5 Daniel 38 M Arquitectura TRUE
## 6 Dell 36 M Informatica FALSE
## 7 Francisco 29 M Sistemas TRUE
## 8 Isaac 43 M Civil FALSE
## 9 Javier 40 M Administracion TRUE
## 10 Jesus 28 M Arquitectura FALSE
## 11 Laura 28 F Informatica TRUE
## 12 Luis 30 M Sistemas FALSE
## 13 Maria 28 F Civil TRUE
## 14 Verenice 45 F Administracion FALSE
## 15 Gabriel 40 M Arquitectura TRUE
## 16 Jeorgina 39 F Informatica FALSE
## 17 Claudia 28 F Sistemas TRUE
## 18 Adriana 32 F Civil FALSE
## 19 Javier 45 M Administracion TRUE
## 20 Ernesto 35 M Arquitectura FALSE
barplot(datos$edades, names.arg = datos$nombres)