[R] Problem about trim the space and add space to force the same nchar
Joerg Maeder
maeder at atmos.umnw.ethz.ch
Wed May 8 10:51:03 CEST 2002
Hello Ken,
for the second problem i wrote two small functions
fusion <- function(what,sep=", "){
if (length(what)>1){
f <- what[1]
for (i in 2:length(what)) f <- paste(f,what[i],sep=sep)
f
} else what
}
align <- function(txt,n=max(nchar(txt)),lbound=T,ch=' ') {
len <- nchar(txt)
v <- substring(fusion(rep(ch,max(len)),sep=''),1,n-len)
if(lbound) paste(txt,v,sep='') else paste(v,txt,sep='')
}
fusion is similary to paste, but creates a single string from a vector.
align take a string (or a vector of them) algn the items
n is the minimal length
lbound defines the kind of align
ch the character that is used a the front/end of each string
does this help?
gruess
joerg
ken_lee wrote:
>
> Dear all,
> First, Can I trim the space like a<-"abc " ==> a<- "abc" or a<-"a b c " ==> a<-"a b c"
> Second, Can I generate a vector has the same length (nchar) like a<-c("mean =10 ",
> "std =1.23",
> "...
>
> Best regards
>
> Ken
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
--
Joerg Maeder .:|:||:..:.||.:: maeder at atmos.umnw.ethz.ch
Tel: +41 1 633 36 25 .:|:||:..:.||.::
http://www.iac.ethz.ch/staff/maeder
PhD student at INSTITUTE FOR ATMOSPHERIC AND CLIMATE SCIENCE (IACETH)
ETH ZÜRICH Switzerland
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list