[Sorry, I seem to have misplaced the original posting, hence I'll reply
here as I haven't seen this solution mentioned yet]
See ?sweep - this is very general function for this sort of operation.
Note that mat is the OP's data as a matrix, not a data frame. This
doesn't work if mat is a data frame.
Won't scale(x,center=F, scale=x[1,]) do the trick?
--
Abhijit
Quoting Gabor Grothendieck <[EMAIL PROTECTED]>:
> This should work whether your data, x, is a data frame or a matrix:
>
> x / x[rep(1, nrow(x)),]
>
>
> On Thu, Jul 3, 2008 at 6:04 PM, Greg Kettler <[EMAIL PROTECTED]>
wrote:
>> Hi,
>
This should work whether your data, x, is a data frame or a matrix:
x / x[rep(1, nrow(x)),]
On Thu, Jul 3, 2008 at 6:04 PM, Greg Kettler <[EMAIL PROTECTED]> wrote:
> Hi,
> I'd like to normalize a dataset by dividing each row by the first row.
> Very simple, right?
> I tried this:
>
>> expt.fluor
on 07/03/2008 05:04 PM Greg Kettler wrote:
Hi,
I'd like to normalize a dataset by dividing each row by the first row.
Very simple, right?
I tried this:
expt.fluor
X1 X2 X3
1 124 120 134
2 165 163 174
3 52 51 43
4 179 171 166
5 239 238 235
first.row <- expt.fluor[1,]
normed <- apply(ex
Try this:
sweep(x, 2, as.numeric(x[1,]), FUN="/")
On Thu, Jul 3, 2008 at 7:04 PM, Greg Kettler <[EMAIL PROTECTED]> wrote:
> Hi,
> I'd like to normalize a dataset by dividing each row by the first row.
> Very simple, right?
> I tried this:
>
> > expt.fluor
> X1 X2 X3
> 1 124 120 134
> 2 165 16
Hi,
I'd like to normalize a dataset by dividing each row by the first row.
Very simple, right?
I tried this:
> expt.fluor
X1 X2 X3
1 124 120 134
2 165 163 174
3 52 51 43
4 179 171 166
5 239 238 235
>first.row <- expt.fluor[1,]
> normed <- apply(expt.fluor, 1, function(r) {r / first.row})
>
6 matches
Mail list logo