On May 22, 2010, at 10:48 PM, Mohan L wrote:

Dear All,

I have an array some thing like this:

avglog
 January  February     March     April       May      June      July
August September
   60102     83397     56774     48785     49010     40572     38175
47037 51402

The class of "avglog" array.
class(avglog)
[1] "array"

str(avglog)
num [1:9(1d)] 60102 83397 56774 48785 49010 ...
- attr(*, "dimnames")=List of 1
 ..$ : chr [1:9] "January" "February" "March" "April" ...

I have to normalize this "avglog" array to 1000. I mean, I need to devide 1000/avglog[1] and have to multiply this to all the elements in the array and need to plot graph Month Vs Index. To achive this I am doing the below
code. I am feeling there may be a simple way to do this.

This would accomplish those two goals in two lines:

> plot(normedavlog <- 1000*avlog/avlog[1], xaxt="n")
> axis(1, at=1:9, labels =names(avlog))

--
David.


value <- matrix (avglog)

value
      [,1]
[1,] 60102
[2,] 83397
[3,] 56774
[4,] 48785
[5,] 49010
[6,] 40572
[7,] 38175
[8,] 47037
[9,] 51402

day1Avg <- value[1]
day1Avg
[1] 60102
ID <- (1000/day1Avg)
ID
[1] 0.01663838
index <- value*ID
index
          [,1]
[1,] 1000.0000
[2,] 1387.5911
[3,]  944.6275
[4,]  811.7034
[5,]  815.4471
[6,]  675.0524
[7,]  635.1702
[8,]  782.6195
[9,]  855.2461

monthcount <- length(avglog)

Month <-  c(1:monthcount)

trend <- cbind(Month,c(index))

colnames(trend) <- c("Month","Index")

trend
      Month  Index
[1,]    1 1000.0000
[2,]    2 1387.5911
[3,]    3  944.6275
[4,]    4  811.7034
[5,]    5  815.4471
[6,]    6  675.0524
[7,]    7  635.1702
[8,]    8  782.6195
[9,]    9  855.2461

any help will be greatly appreciated.

Thanks & Rg
Mohan L

        [[alternative HTML version deleted]]

______________________________________________
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.html
and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT

______________________________________________
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.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to