Solved

R program loop

Posted on 2014-12-06
1
153 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now