TP 2: Data structures in R
y <- matrix(45:64, nr=5, byrow=TRUE)
m <-rbind(matrix(c(10:19,50:59),nc=5,byrow=T),matrix(90:99,nr=2,byrow=T)) m <- m[,-3] m <- matrix(1,nc=4,nr=4)
minmax <- function(vec) {
c(min(vec),max(vec))
}
sqrtndec <- function(vec,n){
sqrt(sort(vec,decreasing=T)[1:n])
}
valuechar <- function(vec,n){
paste("the element number ",n, " of the vector is ",vec[n],sep="")
}
is.sym <- function(mat){
sum(!(mat==t(mat)))==0
}
sqrt(apply(mat,2,sum))
sum(log(apply(mat,1,prod),2))
count.numeric <- function(liste){
sum(sapply(liste,is.numeric))
}