[R] Plotting in R
Ko-Kang Wang
Ko-Kang at xtra.co.nz
Thu May 11 10:25:13 CEST 2000
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list