Hi: There's always prop.table:
I read in your data as a data frame d. Since prop.table() expects a matrix/array as input, > prop.table(as.matrix(d), 2) V2 V3 V4 [1,] NaN 0.53846154 0.3636364 [2,] NaN 0.15384615 0.0000000 [3,] NaN 0.07692308 0.2727273 [4,] NaN 0.23076923 0.3636364 where the second argument indicates that you want column proportions. You can always use round(prop.table(as.matrix(d), 2), 2) to simplify the output to two decimal places. (As you can see, Dr. Harding's comment about zero columns is well placed...) HTH, Dennis On Thu, May 6, 2010 at 10:06 AM, n.via...@libero.it <n.via...@libero.it>wrote: > > Dear list, > Im trying to do the following operation but im not able to do it > This is my table: > 1 2 3 > 1 0 7 4 > 2 0 2 0 > 3 0 1 3 > 4 0 3 4 > > what i would like to do is > > divide each row values with the corresponding column' sum,namely: > > 1 2 3 > 1 0 0.54 0.36 > 2 0 0.15 0 > 3 0 0.08 0.27 > 4 0 0.23 0.36 > > > thanks for your attention > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. > [[alternative HTML version deleted]] ______________________________________________ R-help@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.