Dear all,
Thank you very much for all your valuable suggestions!
Best wishes,
Alexey Shipunov
__
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.htm
Alexey Shipunov wrote:
> Dear list,
>
> I just made a very simple mistake, but it was hard to spot. And I
> think that I should warn other people, because it is probably so
> simple to make...
>
> === R code ===
>
> # Let us create a matrix:
> (a <- cbind(c(0,1,1), rep(1,3)))
>
> # [,1] [
R is working exactly as documented. If you look at how the matrix is
stored (column-wise) and then what you are dividing by, you will see
that it is doing what you asked (when recycling values):
> as.vector(a)
[1] 0 1 1 1 1 1
> as.vector(a)/c(2,3)
[1] 0.000 0.333 0.500 0.333 0.50
and you might want to check ?prop.table
> prop.table(a, 2)
[,1] [,2]
[1,] 0.0 0.333
[2,] 0.5 0.333
[3,] 0.5 0.333
or even ?sweep (which will be useful for more complex situations)
> sweep(a, 2, colSums(a), "/")
[,1] [,2]
[1,] 0.0 0.333
[2,] 0.5 0.333
Dear list,
I just made a very simple mistake, but it was hard to spot. And I
think that I should warn other people, because it is probably so
simple to make...
=== R code ===
# Let us create a matrix:
(a <- cbind(c(0,1,1), rep(1,3)))
# [,1] [,2]
# [1,]01
# [2,]11
# [3,]
5 matches
Mail list logo