[R] more on paste and bug

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Tue Oct 9 16:26:19 CEST 2001


Ott Toomet <siim at obs.ee> writes:

> Hi,
> 
> dput( ce0) gives a correct answer:
> > dput( ce0)
> c("1985", "9", "2", "2", "1", "A", "1", "", "NA", "5", "1999" )
> 
> The same does just print( ce0):
> > print( ce0)
>  [1] "1985" "9"    "2"    "2"    "1"    "A"    "1"    ""     "NA"   "5"
> [11] "1999"
> 
> However, if I make a new similar vector ce0a:
> > ce0a <- c( 1985,9,2,2,1,"A",1,"",NA,5,1999)
> 
> Then the paste works correctly:
> > paste( ce0a, m, sep="", collapse="")
> [1] "1985<1>9<2>2<3>2<4>1<5>A<6>1<7><8>NA<9>5<0>1999END"
> 
> I had M as
> > m
>  [1] "<1>" "<2>" "<3>" "<4>" "<5>" "<6>" "<7>" "<8>" "<9>" "<0>" "END"
> 
> So I have two apparently similar vectors which behave differently with
> paste:
> > paste( ce0a, m, sep="", collapse="")
> [1] "1985<1>9<2>2<3>2<4>1<5>A<6>1<7><8>NA<9>5<0>1999END"
> > paste( ce0, m, sep="", collapse="")
> [1] "1985<1>9<2>2<3>2<4>1<5>A1<7>NA<9>5<0>1999END"
> > ce0a
>  [1] "1985" "9"    "2"    "2"    "1"    "A"    "1"    ""     "NA"   "5"
> [11] "1999"
> > ce0
>  [1] "1985" "9"    "2"    "2"    "1"    "A"    "1"    ""     "NA"   "5"
> [11] "1999"
> 
> I suggest there can be some hidden attributes somewhere in ce0 which I have
> not noticed (there seem not to be factors), the problem seems to arise with
> the non-numerical columns (ce0 is just part of one row of the big
> dataframe).  Is it possible to figure it out, and possible change?  At least
> attributes() do show nothing:
> > attributes(ce0)
> NULL
> > attributes(ce0a)
> NULL

Hmmm. The plot would seem to thicken around the entries in ce0
corresponding to <6> and <8>. If these accidentally contain \0
characters, much would be explained. Maybe also other weird
characters. 

What happens if you do nchar(ce0) ?  What if you omit the collapse=
argument? 

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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