Full_Name: Dirk Jacob Version: R 2.8.1 and 2.9.1 OS: Win XP Submission from: (NULL) (153.96.32.62) I want to convert numbers to strings like:> inputs= c(0.3+0*(1:12) ) > (format(inputs,digits=3,scientific=T,collapse=" "))and it works [1] "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" [10] "3e-01" "3e-01" "3e-01" if I use different numbers it does not:> C <- c(840,1000,1000,1000) > R <- c(860,2500,2500,2000) > L <- c(0.23,1,1,1.1) > T <- c(0.2,0.2,0.3,0.175) > I <- c(0.05,0.1,0.14,0.18) > inputs <- cbind(C,R,L,T,I)If I try the same format command, it does not:> (format(c(inputs[1,]),digits=3, scientific=T))Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3, : invalid 'scientific' argument Only if I change scientific to NA> (format(c(inputs[1,]),digits=3, scientific=NA))remark (not important for the problem): but I need scientific because sometimes the strings get to long otherwise Now if I am trying the same thing as at the beginning it doesn't work anymore> inputs= c(0.3+0*(1:12) ) > (format(inputs,digits=3,scientific=T,collapse=" "))Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3, : invalid 'scientific' argument This looks like some problem in .Internal(format, ...) to me!? if I remove everything from my environment> rm(list=ls(all=T)) > > inputs= c(0.3+0*(1:12) ) > (format(inputs,digits=3,scientific=T,collapse=" "))[1] "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" [10] "3e-01" "3e-01" "3e-01">it works again! rm(list=ls(all=T)) inputs= c(0.3+0*(1:12) ) (format(inputs,digits=3,scientific=T,collapse=" "))
Ha, beautiful example of how you should never use 'T' when you mean 'TRUE'. Thanks /Henrik PS. The error message does indeed give you a great hint what the problem is. On Fri, Nov 13, 2009 at 11:40 AM, <dirk.jacob at ise.fraunhofer.de> wrote:> Full_Name: Dirk Jacob > Version: R 2.8.1 and 2.9.1 > OS: Win XP > Submission from: (NULL) (153.96.32.62) > > > I want to convert numbers to strings > like: >> inputs= c(0.3+0*(1:12) ) >> (format(inputs,digits=3,scientific=T,collapse=" ")) > > and it works > > ?[1] "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" > [10] "3e-01" "3e-01" "3e-01" > > if I use different numbers it does not: > >> C <- c(840,1000,1000,1000) >> R <- c(860,2500,2500,2000) >> L <- c(0.23,1,1,1.1) >> T <- c(0.2,0.2,0.3,0.175) >> I <- c(0.05,0.1,0.14,0.18) >> inputs <- cbind(C,R,L,T,I) > > If I try the same format command, it does not: >> (format(c(inputs[1,]),digits=3, scientific=T)) > Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3, ?: > ?invalid 'scientific' argument > > Only if I change scientific to NA >> (format(c(inputs[1,]),digits=3, scientific=NA)) > > remark (not important for the problem): > but I need scientific because sometimes the strings get to long otherwise > > > Now if I am trying the same thing as at the beginning it doesn't work anymore >> inputs= c(0.3+0*(1:12) ) >> (format(inputs,digits=3,scientific=T,collapse=" ")) > Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3, ?: > ?invalid 'scientific' argument > > This looks like some problem in .Internal(format, ...) to me!? > > if I remove everything from my environment >> rm(list=ls(all=T)) >> >> inputs= c(0.3+0*(1:12) ) >> (format(inputs,digits=3,scientific=T,collapse=" ")) > ?[1] "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" > [10] "3e-01" "3e-01" "3e-01" >> > it works again! > > rm(list=ls(all=T)) > > inputs= c(0.3+0*(1:12) ) > (format(inputs,digits=3,scientific=T,collapse=" ")) > > ______________________________________________ > R-devel at r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-devel >
At 10:40 13/11/2009, dirk.jacob at ise.fraunhofer.de wrote:>Full_Name: Dirk Jacob >Version: R 2.8.1 and 2.9.1 >OS: Win XP >Submission from: (NULL) (153.96.32.62) > > >I want to convert numbers to strings >like: > > inputs= c(0.3+0*(1:12) ) > > (format(inputs,digits=3,scientific=T,collapse=" ")) > >and it works > > [1] "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" >[10] "3e-01" "3e-01" "3e-01" > >if I use different numbers it does not: > > > C <- c(840,1000,1000,1000) > > R <- c(860,2500,2500,2000) > > L <- c(0.23,1,1,1.1) > > T <- c(0.2,0.2,0.3,0.175)So now T has the value?> > I <- c(0.05,0.1,0.14,0.18) > > inputs <- cbind(C,R,L,T,I) > >If I try the same format command, it does not: > > (format(c(inputs[1,]),digits=3, scientific=T)) >Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3, : > invalid 'scientific' argumentIt does work for scientific = TRUE (admittedly I am using R 2.10.0 but I suspect it has been the same for most of this millennium). I do not think this is a bug in R.>Only if I change scientific to NA > > (format(c(inputs[1,]),digits=3, scientific=NA)) > >remark (not important for the problem): >but I need scientific because sometimes the strings get to long otherwise > > >Now if I am trying the same thing as at the beginning it doesn't work anymore > > inputs= c(0.3+0*(1:12) ) > > (format(inputs,digits=3,scientific=T,collapse=" ")) >Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3, : > invalid 'scientific' argument > >This looks like some problem in .Internal(format, ...) to me!? > >if I remove everything from my environment > > rm(list=ls(all=T)) > > > > inputs= c(0.3+0*(1:12) ) > > (format(inputs,digits=3,scientific=T,collapse=" ")) > [1] "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" "3e-01" >[10] "3e-01" "3e-01" "3e-01" > > >it works again! > >rm(list=ls(all=T)) > >inputs= c(0.3+0*(1:12) ) >(format(inputs,digits=3,scientific=T,collapse=" ")) > >______________________________________________ >R-devel at r-project.org mailing list >stat.ethz.ch/mailman/listinfo/r-develMichael Dewey aghmed.fsnet.co.uk
Maybe Matching Threads
- Bug in format.default(): na.encode does not have any effect for (PR#12318)
- interpreting date-related error message
- prettyNum digits=0 not compatible with scientific notation
- prettyNum digits=0 not compatible with scientific notation
- Newbie woes with *apply