This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
You can also embed plots, for example:
#crear un vector
n<-c(13,16,21,48)
#crear un objeto
deportes<-c('futbol','tenis','golf','ciclismo')
#crea un dataframe
nombre=c("messi","luis diaz","mo salah","muñoz")
edad=c(36,27,32,25)
goles=c(800,105,435,76)
posicion=c("delantero","extremo","extremo","lateral")
jugadores<-data.frame(nombre,edad,goles,posicion)
print(data.frame(jugadores))
## nombre edad goles posicion
## 1 messi 36 800 delantero
## 2 luis diaz 27 105 extremo
## 3 mo salah 32 435 extremo
## 4 muñoz 25 76 lateral
#ejercicios
#01
a<-c(2,4,6,8,10,12)
#2
sum(a)
## [1] 42
print(sum(a))
## [1] 42
#3
prod(a)
## [1] 46080
#4
b<-c(1,3,5,7,9)
a-b
## Warning in a - b: longitud de objeto mayor no es múltiplo de la longitud de uno
## menor
## [1] 1 1 1 1 1 11
#5
x<-c(5,10,15,20)
y<-c(6,12,18,22)
#suma
suma_xy<-(x+y)
#producto
producto_xy<-x*y
print(producto_xy)
## [1] 30 120 270 440
#potenciacion
potenciacion_xy<-x^y
print(potenciacion_xy)
## [1] 1.562500e+04 1.000000e+12 1.477892e+21 4.194304e+28
#radicacion
radicacion_xy<-x^(1/y)
print(radicacion_xy)
## [1] 1.307660 1.211528 1.162354 1.145876
#6
#iguales
f<-13
g<-13
#difrentes
h<-5
j<-7
#compararigualdad
igualdad_fg <- f == g # TRUE, porque son iguales
igualdad_hj <- h == j # FALSE, porque son diferentes
# Comparar desigualdad
desigualdad_fg <- f != g # FALSE, porque son iguales
desigualdad_hj <- h != j # TRUE, porque son diferentes
# Mostrar resultados
print(paste("f == g:", igualdad_fg))
## [1] "f == g: TRUE"
print(paste("h == j:", igualdad_hj))
## [1] "h == j: FALSE"
print(paste("f != g:", desigualdad_fg))
## [1] "f != g: FALSE"
paste("h != j:", desigualdad_hj)
## [1] "h != j: TRUE"
Note that the echo = FALSE
parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.