Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Clase 03 Funciones R Studio
Clase 03 Funciones R Studio
id <- 1:n
x <- id[fil== 1]
y <- id[fil== 0]
M[as.matrix(z)] <- 1
M[as.matrix(z)] <- 1
view(M)
#funciones
#cuerpo
return()
#ejemplo1
y <- x^2
}else{ # x>=0
y <- x
}
#ejemplo2
y <- 1
}else{
if(x == k){
y <- 0
}else{
y <- -1
return(y)
func2(3, k=5)
func2(-2, k=5)
# sentencias de control
#for
for(i in 1:n){
#cuerpo
#ejemplo1
n <- 20
for(i in 1:0){
print(i)
#ejemplo
n <- 100
s <- 0
for(i in 1:n){
s <- s + i
#while
while () {
#ejemplo
x <- 0
while(x<10){
print(x)
x <- x+1
}
#ejemplo 3 con while en vez del for
i<- 1
s<- 0
while(i<=100){
s <- s + i
i <- i+1
# repetir
repeat{
#cuerpo
break
#ejemplo1
i <- 0
repeat{
if(i<10){
print(i)
i <- i + 1
}else{
break
#ejemplo2
i <- 1
s <- 0
repat{
if(i<= n){
s <- s + i
i <- i + 1
}else{
break