4. Modos (types) - JulTob/R GitHub Wiki
logical
T F
Numeric
Reals
a+b
a-b
a*b
a/b
a^b
exp
sqrt
a==b
a!=b
a<b
a<=b
a>b
a>=b
Complex
Complex
Character
'a'
Composed Objects
Vector
> vect<-c(1,2,3,5,7)
> mode(vect)
[1] "numeric"
> length(vect)
[1] 5
> names<-c("John","Ned","Sansa")
> starks<-c("Rob",names)
> starks
[1] "Rob" "John" "Ned" "Sansa"
> mode(starks)
[1] "character"
> length(starks)
[1] 4
> x<-c(-5:5)
> x[1:3]
[1] -5 -4 -3
> x[2]<-0
> x
[1] -5 0 -3 -2 -1 0 1 2 3 4 5
> x<-c(1:9)
> sqrt(x)
[1] 1.000000 1.414214 1.732051 2.000000 2.236068 2.449490 2.645751 2.828427
[9] 3.000000
Se pueden multiplicar, sumar, etc., vectores de la misma longitud, obte- niendo as ́ı un nuevo vector en donde se han multiplicado, sumando, etc., los elementos de cada uno de los vectores:
> x1<-c(0:3)
> x2<-c(1:4)
> x1+x2
[1] 1 3 5 7
> x1*x2
[1] 0 2 6 12
> x1-x2
[1] -1 -1 -1 -1
> x1/x2
[1] 0.0000000 0.5000000 0.6666667 0.7500000
>
> z<-c(5,3,4)
> names(z)<-c("hipot","cat1","cat2")
> z
hipot cat1 cat2
5 3 4
> names(z)
> names(z)
[1] "hipot" "cat1" "cat2"
Matrix
> A<-matrix(c(1,2,3,4,5,6,7,8),ncol=4)
> A
[,1] [,2] [,3] [,4]
[1,] 1 3 5 7
[2,] 2 4 6 8
> A<-matrix(c(1,2,3,4,5,6,7,8),nrow=4)
> A
[,1] [,2]
[1,] 1 5
[2,] 2 6
[3,] 3 7
[4,] 4 8
> A<-matrix(c(1,2,3,4,5,6,7,8),nrow=2,ncol=2)
> A
[,1] [,2]
[1,] 1 3
[2,] 2 4
> a
Error: object 'a' not found
B<-cbind(c(1:3),c(4:6))
> B
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6
> dim(B)
[1] 3 2
> t(B)
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
> C<- matrix(c(1,2,3,4,5,6,7,8), ncol=4, dimnames=list(c("Fila1","Fila2"),c("Col1","Col2","Col3","Col4")))
> C
Col1 Col2 Col3 Col4
Fila1 1 3 5 7
Fila2 2 4 6 8
Factor
Values from limited categories.
Cara//Cruz.
data frame
Columns of different types, excel similar.
##list mixed types