[R] Calculate percentages in a table of data

jim holtman jholtman at gmail.com
Thu Nov 8 22:40:16 CET 2007


This will do the calculations and the plot:

> x <- scan(textConnection("255 0 255 0 255 255 255 0 255 0
+ 255 255 255 255 0 255 255 0 255 0
+ 255 255 255 255 255 255 255 0 255 0
+ 255 255 255 255 0 255 255 0 255 0
+ 255 255 0 255 255 255 255 0 255 0
+ 255 255 255 0 255 0 0 255 0 255"), what=0)
Read 60 items
> x <- matrix(x, ncol=10, byrow=TRUE)
> num.zeros <- apply(x, 1, function(z) sum(z == 0))
> num.zeros * 10
[1] 40 30 20 30 30 40
> plot(num.zeros * 10, type='o')
>


On Nov 8, 2007 1:54 PM, Luca Penasa <luca.penasa at email.it> wrote:
> Hi everybody,
> Im a newbie, but i hope someone can help me in this work...
> Ill try to explain what i need to do in the best way, but my english is
> not good...
> Iv imported a big table of data, this table is something like this:
>
> 255 0 255 0 255 255 255 0 255 0
> 255 255 255 255 0 255 255 0 255 0
> 255 255 255 255 255 255 255 0 255 0
> 255 255 255 255 0 255 255 0 255 0
> 255 255 0 255 255 255 255 0 255 0
> 255 255 255 0 255 0 0 255 0 255
>
> I need to calculate for every row the number of cells with "255" and the
> number of cells with "0"... from this values i would like to obtain the
> percentage of 0 presents in the row.... after i want to plot the data in
> a graph showing the variations of this percentage along the rows...
>
> What i want to obtain is an array of this type:
> 40
> 30
> 20
> 30
> 30
> 40
>
> Someone can give me a hint on how to obtain this?? maybe anybody can
> suggest me the functions i could use...
>
> what software do you suggest me for plot the data?? i was thinking in
> gnuplot.... so i can plot the graph in svg format...
>
> Please help me
>
> thank you
>
> Luca Penasa,
> geology student,
> University of Padua, Italy
>
>
>
>
>
>
>  --
>  Email.it, the professional e-mail, gratis per te: http://www.email.it/f
>
>  Sponsor:
>  Fai conoscere la tua azienda con l'invio di newsletter e campagne email marketing. Con soli 250 Euro incrementi la tua visibilità!
> *
>  Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=7150&d=8-11
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list