# Re: [R] how to manipulate counts matrix?

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Wed 18 Oct 2006 - 18:59:46 GMT

# Assume rn holds the rownames of the table # rn <- rownames(my.table)

rn <- c("[-11.9,-10.6]", "(-10.6,-9.3]", "(-9.3,-8.01]", "(-8.01,-6.73]")

# 1
library(gsubfn)
colMeans(strapply(rn, "[-.0-9]+", as.numeric, simplify = TRUE))

# 2
library(gsubfn)
strapply(rn, "([-.0-9]+), *([-.0-9]+)",

~ (as.numeric(x) + as.numeric(y))/2, backref = -2, simplify = TRUE)

# 3

The gsubfn demo

library(gsubfn)
demo("gsubfn-cut")

shows a similar problem to his one.

> Hi List,
>
> I've got a count matrix like this:
>
>
> [-11.9,-11] (-11,-10.2] (-10.2,-9.3] (-9.3,-8.44]
> [-11.9,-10.6] 0 0 0 0

> (-10.6,-9.3] 0 0 0 0
> (-9.3,-8.01] 0 0 0 0
> (-8.01,-6.73] 0 0 0 0

>
> I want to manipulate the matrix by taking the average of each range, eg. [-11.9,-11] as (-11.9-11)/2. I've tried R introduction and site search, but not able to find information relevant.
>
> Thanks!
>
> Jen
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help