[R] Find longuest string in a character list

arun smartpink111 at yahoo.com
Wed May 29 20:23:46 CEST 2013


May be this helps:

mymatrix<- matrix (1:5, nrow=5, ncol=columnas, byrow=TRUE, dimnames=(list(myrownames, c(1,2,3,4,5)))) 
#Error in matrix(1:5, nrow = 5, ncol = columnas, byrow = TRUE, dimnames = (list(myrownames,  : 
 # object 'columnas' not found

myrownames[which.max(nchar(myrownames))]
#[1] "Ciencias Sociales y Jurídicas"
nchar(myrownames)[which.max(nchar(myrownames))]
#[1] 29
A.K.


>Hello, 
>
>I want to modify margin options in a barplot into a loop. I have, for example, a matrix like this: 
>
>myrownames <- c("Arte y Humanidades","Ciencias Sociales y 
Jurídicas", "Ciencias de la Salud","Ciencias", "Ingenierías y 
arquitectura") 
>mymatrix<- matrix (1:5, nrow=5, ncol=columnas, byrow=TRUE, dimnames=(list(myrownames, c(1,2,3,4,5)))) 
>my_strings_length <- nchar(rownames(mymatrix)) 
>[1] 18 29 20  8 26 
>
>I want to find automatically the highest  value in my_strings_length, i.e 29. ¿how can I do it? 
>
>many thanks, 
>
>-- 
>================================== 
>Ramón Ovelar 
>Campus Virtual Birtuala UPV/EHU 
>Tel: (34) 94 601 3407 
>http://campusvirtual.ehu.es
>University of the Basque Country



More information about the R-help mailing list