help to indexing data frame

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

help to indexing data frame

mohan L
Dear All,

I have data some thing like this:

> sample
State    Jan   Feb     Mar
A          1       1         1
B        1298   1293    1294
C        0        0         0
D        5        5         5
E       18      18       18

I need to  multiply  "Jan"  column *1000 and divided by the same number,
like this :

> data[,-(1:2)] * ((data[,2] *1000)/data[ ,2])

I doing some thing wrong with the above to get below result.

What I actually need is :


State    Jan                      Feb                            Mar
A          1*1000/1               1*1000/1                  1*1000/1
B        1298*1000/1298     1293*1000/1298       1294
C        0                            0                             0
D        5                            5                             5
E       18                           18                           18

Here "Jan" base for me .  Any help will be greatly appreciated.

Thanks & Rg
Mohan L

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: help to indexing data frame

mohan L
On Fri, May 21, 2010 at 11:27 AM, Mohan L <[hidden email]> wrote:

>
> Dear All,
>
> I have data some thing like this:
>
> > sample
> State    Jan   Feb     Mar
> A          1       1         1
> B        1298   1293    1294
> C        0        0         0
> D        5        5         5
> E       18      18       18
>
> I need to  multiply  "Jan"  column *1000 and divided by the same number,
> like this :
>
> > data[,-(1:2)] * ((data[,2] *1000)/data[ ,2])
>

> data[,-(1:2)] * 1000/data[ ,2]

It will work as I expected. I have "0" in the "C" row. After the calculation
it gives  "NaN" zero place. But I need there zero instead of NaN.

There may be some solution for this.

Thanks & Rg
Mohan L

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.