Solved

R program loop

Posted on 2014-12-06
1
161 Views
Last Modified: 2014-12-06
Hi,

The following code gives me an error:
Error: unexpected '{' in:
"for(i in 1 : nrow(VarM)) {
  for (j in 1 : ncol(VarM) {"
>     CorrM[i,j] = VarM[i,j]/(SDM[i,1]*SDM[j,1])
Error: object 'i' not found
>   }
Error: unexpected '}' in "  }"
> }
Error: unexpected '}' in "}"


Code:
VarM = matrix(c(.0016,.001,.0015,.001,.002,.0019,.0015,.0019,.0042),nrow=3,byrow = TRUE)
A = VarM[1,1]
SD_A = sqrt(A)
B = VarM[2,2]
SD_B = sqrt(B)
C = VarM[3,3]
SD_C = sqrt(C)
SDM = matrix(c(SD_A,SD_B,SD_C),nrow=3,byrow=TRUE)
SDM
CorrM=matrix(data=NA, nrow=3, ncol=3, byrow=TRUE)
for(i in 1 : nrow(VarM)) {
  for (j in 1 : ncol(VarM) {
    CorrM[i,j] = VarM[i,j]/(SDM[i,1]*SDM[j,1])
  }
}

Thanks
0
Comment
Question by:camper12
1 Comment
 
LVL 14

Accepted Solution

by:
brendanmeyer earned 500 total points
ID: 40485120
"for(i in 1 : nrow(VarM)) {
  for (j in 1 : ncol(VarM) {"

Open in new window



on the for(j in line

you need an extra )

"for(i in 1 : nrow(VarM)) {
  for (j in 1 : ncol(VarM)) {"

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Lithium-ion batteries area cornerstone of today's portable electronic devices, and even though they are relied upon heavily, their chemistry and origin are not of common knowledge. This article is about a device on which every smartphone, laptop, an…
When we purchase storage, we typically are advertised storage of 500GB, 1TB, 2TB and so on. However, when you actually install it into your computer, your 500GB HDD will actually show up as 465GB. Why? It has to do with the way people and computers…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question