what is wrong with for and if cycle in R

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

what is wrong with for and if cycle in R

Jie TANG-3
hi
 I used a two nested cycle by if and for by such code

for(ity in 1:4)
{
if (ity==1£©
{
print(ity)
}
}

when I run the code it failed and R tell me that
"error: unrespected '}' in "}""

and when I reduce a }

for(ity in 1:4)
{
if (ity==2£©
{
print(ity)
}

R will print 4 but not 2 as what I repect

Could anyone tell me what is the matter with R and how to modify it?

thank you .
--
TANG Jie

        [[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: what is wrong with for and if cycle in R

Ingmar Visser
I get this error below, there seems to be hidden character in your
input instead of a parenthesis:

> for(ity in 1:4)
+ {
+ if (ity==1)
Error: unexpected input in:
"{
if (ity==1Ô"
> {
+ print(ity)
+ }
Error in print(ity) : object 'ity' not found
> }
Error: unexpected '}' in "}"
>

hth, Ingmar


On Thu, Dec 19, 2013 at 10:07 AM, Jie Tang <[hidden email]> wrote:

> hi
>  I used a two nested cycle by if and for by such code
>
> for(ity in 1:4)
> {
> if (ity==1)
> {
> print(ity)
> }
> }
>
> when I run the code it failed and R tell me that
> "error: unrespected '}' in "}""
>
> and when I reduce a }
>
> for(ity in 1:4)
> {
> if (ity==2)
> {
> print(ity)
> }
>
> R will print 4 but not 2 as what I repect
>
> Could anyone tell me what is the matter with R and how to modify it?
>
> thank you .
> --
> TANG Jie
>
>         [[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.
>

______________________________________________
[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: what is wrong with for and if cycle in R

Pascal Oettli-2
In reply to this post by Jie TANG-3
Hi,

It seems the right prenthesis ")" in the "if" statement is in
different encoding.

>From your script:
> charToRaw('if (ity==1)')[11:13]
[1] ef bc 89

> charToRaw(')')
[1] 29

 By changing the right parenthesis, it works fine.

HTH,
Pascal

On 19 December 2013 18:07, Jie Tang <[hidden email]> wrote:

> hi
>  I used a two nested cycle by if and for by such code
>
> for(ity in 1:4)
> {
> if (ity==1)
> {
> print(ity)
> }
> }
>
> when I run the code it failed and R tell me that
> "error: unrespected '}' in "}""
>
> and when I reduce a }
>
> for(ity in 1:4)
> {
> if (ity==2)
> {
> print(ity)
> }
>
> R will print 4 but not 2 as what I repect
>
> Could anyone tell me what is the matter with R and how to modify it?
>
> thank you .
> --
> TANG Jie
>
>         [[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.
>



--
Pascal Oettli
Project Scientist
JAMSTEC
Yokohama, Japan

______________________________________________
[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.