Here is a question that I don''t know if it is possible to do in R: If I type:> log(1:1000)Then, I want to "take out" the first decimal place of each output, plot them based on their appearence frequencies. Then take the second decimal place, do the same thing. Actually, I suspect I don''t have to write a function to do this. Is it possible to do this? Get the first decimal place of each answer to log(1:1000), then plot them? Thanks -- ----------------------------------------------------------------------------------- Ko-Kang Wang Undergraduate Student Computer Science/Statistics Double Major University of Auckland Auckland 1005 New Zealand ----------------------------------------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "KKWa" == Ko-Kang Wang <Ko-Kang at xtra.co.nz> writes:KKWa> Here is a question that I don''t know if it is possible to do in R: KKWa> If I type: >> log(1:1000) KKWa> Then, I want to "take out" the first decimal place of each KKWa> output, plot them based on their appearence frequencies. Then KKWa> take the second decimal place, do the same thing. KKWa> Actually, I suspect I don''t have to write a function to do this. KKWa> Is it possible to do this? Get the first decimal place of each KKWa> answer to log(1:1000), then plot them? ## I hope this is not your home work assignment; ## The following is actually pretty neat .. (propria laus sordet) x <- 1:1000 ndig <- 6 (ii <- as.integer(10^(ndig-1) * log(x)))[1:7] (ci <- formatC(ii, flag="0", wid= ndig))[1:7] cm <- t(sapply(ci, function(cc) strsplit(cc,NULL)[[1]])) cm [1:7,] apply(cm, 2, table) #--> Nice tables # The plots : par(mfrow= c(3,2), lab = c(10,10,7)) for(i in 1:ndig) hist(as.integer(cm[,i]), breaks = -.5 + 0:10, main = paste("Distribution of ", i,"-th digit")) ---- Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thank you very much. No this is not an assignment. I just want to test Benford''s Law. However it''s kind of interesting to see that the digit 1 does not appear as frequently as it should be. But anyway, thank you very much. Martin Maechler wrote:> >>>>> "KKWa" == Ko-Kang Wang <Ko-Kang at xtra.co.nz> writes: > > KKWa> Here is a question that I don''t know if it is possible to do in R: > KKWa> If I type: > >> log(1:1000) > > KKWa> Then, I want to "take out" the first decimal place of each > KKWa> output, plot them based on their appearence frequencies. Then > KKWa> take the second decimal place, do the same thing. > > KKWa> Actually, I suspect I don''t have to write a function to do this. > KKWa> Is it possible to do this? Get the first decimal place of each > KKWa> answer to log(1:1000), then plot them? > > ## I hope this is not your home work assignment; > ## The following is actually pretty neat .. (propria laus sordet) > > x <- 1:1000 > > ndig <- 6 > > (ii <- as.integer(10^(ndig-1) * log(x)))[1:7] > (ci <- formatC(ii, flag="0", wid= ndig))[1:7] > cm <- t(sapply(ci, function(cc) strsplit(cc,NULL)[[1]])) > cm [1:7,] > > apply(cm, 2, table) #--> Nice tables > > # The plots : > par(mfrow= c(3,2), lab = c(10,10,7)) > for(i in 1:ndig) > hist(as.integer(cm[,i]), breaks = -.5 + 0:10, > main = paste("Distribution of ", i,"-th digit")) > > ---- > Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ > Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27 > ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND > phone: x-41-1-632-3408 fax: ...-1228 <><-- ----------------------------------------------------------------------------------- Ko-Kang Wang Undergraduate Student Computer Science/Statistics Double Major University of Auckland Auckland 1005 New Zealand ----------------------------------------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>Here is a question that I don''t know if it is possible to do in R: > >If I type: >> log(1:1000) > >Then, I want to "take out" the first decimal place of each output, plot >them based on their appearence frequencies. Then take the second >decimal place, do the same thing.Try: a_ log(1:1000) d1_floor(10*(a-floor(a))) # first decimal par(mfrow=c(2,2)) hist(d1,breaks=c(-1:9)) table(d1) d2_floor(10*(10*a-floor(10*a))) # second decimal hist(d2,breaks=c(-1:9)) table(d2)> >Actually, I suspect I don''t have to write a function to do this. Is it >possible to do this? Get the first decimal place of each answer to >log(1:1000), then plot them? > >Thanks > >-- >-----------------------------------------------------------------------------------> > Ko-Kang Wang > Undergraduate Student > Computer Science/Statistics Double Major > University of Auckland > Auckland 1005 > New Zealand >-----------------------------------------------------------------------------------> > > >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.->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 >_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._>Yudi Pawitan yudi at stat.ucc.ie Department of Statistics UCC Cork, Ireland Ph 353-21-490 2906 Fax 353-21-427 1040 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
At 10:03 11/05/00 +0200, you wrote:>## I hope this is not your home work assignment; >## The following is actually pretty neat .. (propria laus sordet) > >x <- 1:1000 > >ndig <- 6 > > (ii <- as.integer(10^(ndig-1) * log(x)))[1:7] > (ci <- formatC(ii, flag="0", wid= ndig))[1:7] > cm <- t(sapply(ci, function(cc) strsplit(cc,NULL)[[1]])) > cm [1:7,] > >apply(cm, 2, table) #--> Nice tables > ># The plots : >par(mfrow= c(3,2), lab = c(10,10,7)) >for(i in 1:ndig) > hist(as.integer(cm[,i]), breaks = -.5 + 0:10, > main = paste("Distribution of ", i,"-th digit"))Here is my solution (just for the tables): x <- log(1:1000) for (i in 1:6) print(table(as.integer((x %% (10/10^i))*10^i))) (I''m surprised it works...) Emmanuel Paradis -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._