Question

J'utilise strsplit dans R pour ajouter des noms au boxplot mais cela me donne une erreur.

strng <- "one%two%three"
tt <- strsplit(strng,"%",fixed=TRUE)

et puis

boxplot(param~grp,data=snp,horizontal=TRUE,names=tt)

cela donne

ls = list(c("one", "two",  :
  'at' and 'labels' lengths differ, 3 != 1
Calls: boxplot ... boxplot.default -> do.call -> bxp -> do.call -> axis
Execution halted

l'argument noms nécessite un vecteur et strsplit renvoie une liste.Sont-ils incompatibles ?

Si je fais

boxplot(param~grp,data=snp,horizontal=TRUE,names=c("on","two","three"))

Alors c'est ok.

Merci beaucoup pour votre aide

Était-ce utile?

La solution

Utiliser tt[[1]] ou unlist(tt) au lieu de tt

boxplot(param~grp,data=snp,horizontal=TRUE,names=tt[[1]])

names l'argument attend un vecteur et tt est une liste, vous devez donc transmettre un vecteur et non une liste.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top