|
Dear all,
The following function code fails with errors (see below): RegPlots <- function (data, ContrVar, RespVar){ intNmbrRows<-length(RespVar);intNmbrCols<-lenght(ContrVar) par(mfrow=c(intNmbrRows,intNmbrCols)) For(i in 1:intNmbrRows){ For (j in 1:intNmbrCols){ RegGraf(data,ContrVar[i],RespVar[j]) } } par(mfrow=c(1,1)) #(RegGraf is another function that creates a plot and that runs flawlessly) Output (translated to english): > RegPlots <- function (data, ContrVar, RespVar){ + intNmbrRows<-length(RespVar);intNmbrCols<-lenght(ContrVar) + par(mfrow=c(intNmbrRows,intNmbrCols)) + For(i in 1:intNmbrRows){ Error: Unexpected 'in' in: " par(mfrow=c(intNmbrRows,intNmbrCols)) For(i in" > For (j in 1:intNmbrCols){ Error: Unexpected 'in' in " For (j in" > RegGraf(data,ContrVar[i],RespVar[j]) Error in RegGraf(data, ContrVar[i], RespVar[j]) : Object 'ContrVar' not found > } Error: Unexpected '}' in " }" > } Error: Unexpected '}' in " }" > par(mfrow=c(1,1)) Can someone please show me what is wrong? Thanks in advance Holger ______________________________________________ [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. |
|
Hello,
Generally those error messages refer to something that preceeds them. This is the current case: the parser is expecting a function's argument. The function name is 'For' with uppercase 'F'. The first argument is 'i', then there should be a comma before a second argument. The solution is obviously to write 'for', with lowercase 'f'. Hope this helps, Rui Barradas Em 10-08-2012 22:15, Dr. Holger van Lishaut escreveu: > Dear all, > > The following function code fails with errors (see below): > > RegPlots <- function (data, ContrVar, RespVar){ > intNmbrRows<-length(RespVar);intNmbrCols<-lenght(ContrVar) > par(mfrow=c(intNmbrRows,intNmbrCols)) > For(i in 1:intNmbrRows){ > For (j in 1:intNmbrCols){ > RegGraf(data,ContrVar[i],RespVar[j]) > } > } > par(mfrow=c(1,1)) > > #(RegGraf is another function that creates a plot and that runs > flawlessly) > > Output (translated to english): > >> RegPlots <- function (data, ContrVar, RespVar){ > + intNmbrRows<-length(RespVar);intNmbrCols<-lenght(ContrVar) > + par(mfrow=c(intNmbrRows,intNmbrCols)) > + For(i in 1:intNmbrRows){ > Error: Unexpected 'in' in: > " par(mfrow=c(intNmbrRows,intNmbrCols)) > For(i in" >> For (j in 1:intNmbrCols){ > Error: Unexpected 'in' in " For (j in" >> RegGraf(data,ContrVar[i],RespVar[j]) > Error in RegGraf(data, ContrVar[i], RespVar[j]) : > Object 'ContrVar' not found >> } > Error: Unexpected '}' in " }" >> } > Error: Unexpected '}' in " }" >> par(mfrow=c(1,1)) > > Can someone please show me what is wrong? > > Thanks in advance > Holger > > ______________________________________________ > [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. ______________________________________________ [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. |
|
Am 11.08.2012, 01:18 Uhr, schrieb Rui Barradas <[hidden email]>:
> [...] The solution is obviously to write 'for', with lowercase 'f'. > > Hope this helps, Dear Mr Barradas, indeed it did help, thank you very much! Best regards Holger van Lishaut ______________________________________________ [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. |
|
In reply to this post by Rui Barradas
Am 11.08.2012, 01:18 Uhr, schrieb Rui Barradas <[hidden email]>:
> [...] The solution is obviously to write 'for', with lowercase 'f'. > > Hope this helps, Dear Mr Barradas, indeed it did help, thank you very much! Best regards Holger van Lishaut ______________________________________________ [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. |
|
In reply to this post by Dr. Holger van Lishaut
There is no command "For" in R. It is "for" and R is case sensitive.
---------------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77843-4352 > -----Original Message----- > From: [hidden email] [mailto:r-help-bounces@r- > project.org] On Behalf Of Dr. Holger van Lishaut > Sent: Friday, August 10, 2012 4:16 PM > To: [hidden email] > Subject: [R] Function definition: where is the error in the "for" loop? > > Dear all, > > The following function code fails with errors (see below): > > RegPlots <- function (data, ContrVar, RespVar){ > intNmbrRows<-length(RespVar);intNmbrCols<-lenght(ContrVar) > par(mfrow=c(intNmbrRows,intNmbrCols)) > For(i in 1:intNmbrRows){ > For (j in 1:intNmbrCols){ > RegGraf(data,ContrVar[i],RespVar[j]) > } > } > par(mfrow=c(1,1)) > > #(RegGraf is another function that creates a plot and that runs > flawlessly) > > Output (translated to english): > > > RegPlots <- function (data, ContrVar, RespVar){ > + intNmbrRows<-length(RespVar);intNmbrCols<-lenght(ContrVar) > + par(mfrow=c(intNmbrRows,intNmbrCols)) > + For(i in 1:intNmbrRows){ > Error: Unexpected 'in' in: > " par(mfrow=c(intNmbrRows,intNmbrCols)) > For(i in" > > For (j in 1:intNmbrCols){ > Error: Unexpected 'in' in " For (j in" > > RegGraf(data,ContrVar[i],RespVar[j]) > Error in RegGraf(data, ContrVar[i], RespVar[j]) : > Object 'ContrVar' not found > > } > Error: Unexpected '}' in " }" > > } > Error: Unexpected '}' in " }" > > par(mfrow=c(1,1)) > > Can someone please show me what is wrong? > > Thanks in advance > Holger > > ______________________________________________ > [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. ______________________________________________ [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. |
| Powered by Nabble | Edit this page |
