[R] Calculate percentages in a table of data

Jim Lemon jim at bitwrit.com.au
Fri Nov 9 11:46:29 CET 2007


Luca Penasa 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...
> 
If I understand this, "freq" in prettyR might give the result you want, e.g.

library(prettyR)
apply(as.matrix(big.table),1,freq)

Jim



More information about the R-help mailing list