Because we want the values in table(x[,2]) where the **names** are
as.character(x[,1][x[,1] > 0])], not the positions x[,1][x[,1] > 0])].
Best
On Thu, Jan 15, 2009 at 10:59 AM, Guillaume Chapron <
carnivorescie...@gmail.com> wrote:
> table(x2)[as.character(x[,1][x[,1] > 0])]
>>
>
> Why do I need
Because we want the values in table(x[,2]) where the **names** are
as.character(x[,1][x[,1] > 0])], not the positions x[,1][x[,1] > 0])].
Thanks!
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the p
table(x2)[as.character(x[,1][x[,1] > 0])]
Why do I need as.character() here? I checked it does not work without,
but I don't see why. The help says "as.character attempts to coerce
its argument to character type".
Thanks very much!
Guillaume
__
Guillaume,
# First, you need "extract" the values of x[,1] greater than 0:
x[,1][x[,1] > 0]
# After, you want the number of times that appears in the second column:
table(x2)
# but only to values above:
table(x2)[as.character(x[,1][x[,1] > 0])]
# Now, just put the values in column 2:
x[,2][x[,1
Thank you! This is exactly what I wanted. Could you please explain the
logic behind your code?
x[,2][x[,1][x[,1] > 0]] <- table(x[,2])[as.character(x[,1][x[,1] >
0])]
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-he
Try this:
x[,2][x[,1][x[,1] > 0]] <- table(x[,2])[as.character(x[,1][x[,1] > 0])]
On Thu, Jan 15, 2009 at 10:36 AM, Guillaume Chapron <
carnivorescie...@gmail.com> wrote:
> Hello,
>
> I create this array:
>
> x <- cbind(c(1:4, rep(0,10)), c(rep(0,4), 1:2, rep(3,6), 4,5))
>
> [,1] [,2]
> [1
Hello,
I create this array:
x <- cbind(c(1:4, rep(0,10)), c(rep(0,4), 1:2, rep(3,6), 4,5))
[,1] [,2]
[1,]10
[2,]20
[3,]30
[4,]40
[5,]01
[6,]02
[7,]03
[8,]03
[9,]03
[10,]03
[11,]03
[12,]0
7 matches
Mail list logo