Practica No. 4 Comparaciones

Manejo de Operadores de comparacion, Realizar expresiones de comparacion

haciendo uso de los operadores de comparacion, mediante uso de operadores de

comparacion y ejecutar expresiones conforme a su sintaxis.

Asignacion de variables

vint1 <- 3 
print('vint1')
## [1] "vint1"
vint1
## [1] 3
vint2 <- 6 
print('vint2')
## [1] "vint2"
vint2
## [1] 6
vint3 <- 9
print('vint3')
## [1] "vint3"
vint3
## [1] 9
vdou1 <- 5.6
print('vdou1')
## [1] "vdou1"
vdou1
## [1] 5.6
vdou2 <- 6.5
print('vdou2')
## [1] "vdou2"
vdou2
## [1] 6.5
vchar1 <- 'ABEL'
print('vchar1')
## [1] "vchar1"
vchar1
## [1] "ABEL"
vchar2 <- 'LUNA'
print('vchar2')
## [1] "vchar2"
vchar2
## [1] "LUNA"
vchar3 <-'DANTE'
print('vchar3')
## [1] "vchar3"
vchar3
## [1] "DANTE"

Realizar una comparacion < entre dos valores numericos

print('vint1')
## [1] "vint1"
vint1
## [1] 3
print('vint2')
## [1] "vint2"
vint2
## [1] 6
print ('vint1 < vint2')
## [1] "vint1 < vint2"
vres <-(vint1 < vint2)

vres
## [1] TRUE

Realizar una expresion de comparar > entre dos valores tipo numericos

print('vint1')
## [1] "vint1"
vint1
## [1] 3
print('vint2')
## [1] "vint2"
vint2
## [1] 6
print ('vint1 > vint2')
## [1] "vint1 > vint2"
vres <- (vint1 > vint2)

vres
## [1] FALSE

Realizar una expresion de comparar <= entre dos valores tipo double

print('vdou1')
## [1] "vdou1"
vdou1
## [1] 5.6
print('vdou2')
## [1] "vdou2"
vdou2
## [1] 6.5
print ('vdou2<=vdou1')
## [1] "vdou2<=vdou1"
vres <- (vdou2<=vdou1)
vres
## [1] FALSE

Realizar una expresion de comparar >= entre dos valores tipo double

print('vdou1')
## [1] "vdou1"
vdou1
## [1] 5.6
print('vdou2')
## [1] "vdou2"
vdou2
## [1] 6.5
print('vdou2 >= vdou1')
## [1] "vdou2 >= vdou1"
vres <- (vdou2>=vdou1)
vres
## [1] TRUE

Evaluar cualquier expresion mediante eval()

print('vchar1')
## [1] "vchar1"
vchar1
## [1] "ABEL"
print('vchar2')
## [1] "vchar2"
vchar2
## [1] "LUNA"
eval( vchar2 == vchar1)
## [1] FALSE
eval
## function (expr, envir = parent.frame(), enclos = if (is.list(envir) || 
##     is.pairlist(envir)) parent.frame() else baseenv()) 
## .Internal(eval(expr, envir, enclos))
## <bytecode: 0x00000000106b48a0>
## <environment: namespace:base>

Comparar dos variables tipo char si son iguales o diferentes y presentar el resultado

print('vchar2')
## [1] "vchar2"
vchar2
## [1] "LUNA"
print('vchar1')
## [1] "vchar1"
vchar1
## [1] "ABEL"
print('vchar3')
## [1] "vchar3"
vchar3
## [1] "DANTE"
print ('vchar1 != vchar2' )
## [1] "vchar1 != vchar2"
vchar2 != vchar2
## [1] FALSE
print ('vchar3 == vchar1' )
## [1] "vchar3 == vchar1"
vchar3 == vchar1
## [1] FALSE

Determinar si un valor entero es entero is.integer y presentar en pantalla

print('vdou1')
## [1] "vdou1"
vdou1
## [1] 5.6
print('vdou1 es entero')
## [1] "vdou1 es entero"
vres <- is.integer(vdou1)
vres
## [1] FALSE

Determinar si un valor es double y presentar en pantalla

print('vdou2')
## [1] "vdou2"
vdou2
## [1] 6.5
print('vdou2 es doble')
## [1] "vdou2 es doble"
vres <- is.double(vdou2)
vres
## [1] TRUE

Determinar si un valor es tipo character y presentar en pantalla

print('vchar2')
## [1] "vchar2"
vchar2
## [1] "LUNA"
print('vchar2 es tipo character')
## [1] "vchar2 es tipo character"
vres <- is.character(vchar2)
vres
## [1] TRUE

Determinar si su valor es logico

print('vint3')
## [1] "vint3"
vint3
## [1] 9
print('vint3 es tipo logico')
## [1] "vint3 es tipo logico"
vres <-is.logical(vint3)
vres
## [1] FALSE