Domanda

Sto usando strsplit in r per aggiungere nomi a boxplot ma questo mi dà un errore.

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

e poi

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

Questo rendimento

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'argomento nomi richiede un vettore e strsplit restituisce un elenco.Sono incompatibili?

se faccio

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

Allora va bene.

Grazie mille per il tuo aiuto

È stato utile?

Soluzione

Utilizzare tt[[1]] o unlist(tt) anziché tt

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

L'argomento names si aspetta che un vettore e tt sia un elenco, quindi è necessario passare un vettore non un elenco.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top