R - Is for(x in x) valid?

Phillip Chaffee

I am writing a function in R and have an input id that is a numeric vector.

Can I write a for loop that states:

for(id in id)
{
    /****/
}

and loop over the id vector with the variable id or will this cause problem?

G. Grothendieck

It will produce the expected result but it will destroy the id to the right of the in. Also within the loop all references to id will be the id to the left of in so you won't be able to reference the one on the right.

> id <-  1:3
> for(id in id) print(id)
[1] 1
[1] 2
[1] 3
> id
[1] 3

Try writing it like this to be safer:

ids <- 1:3
for(id in ids) print(id)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Why is `2 + x = 7` valid Haskell?

From Dev

Why is 'let x = 1' valid F# expression?

From Dev

Binding valid checkbox to enable button angularjs 1.2.x

From Dev

Converting a SSL Cert string into a valid X509_STORE_CTX

From Dev

Is Type(::x); valid?

From Dev

How to make a valid input for "xxd -r" in vim when removing a byte?

From Dev

'x64_mingw' is not a valid platform

From Dev

Check valid values of likert scales in R

From Dev

What constitutes a valid symbol (identifier) in R

From Dev

Merge r brings error "'by' must specify uniquely valid columns"

From Dev

int[] table = new int[10],x; is valid syntax?

From Dev

Why is {x:Null} no longer a valid value in a Style Setter in UWP?

From Dev

Valid syntax in both Python 2.x and 3.x for raising exception?

From Dev

C++: int x[+30] is a valid declaration?

From Dev

X509 certificate signed with bouncy castle is not valid

From Dev

SilverStripe dependent dropdown - x is not a valid option

From Dev

how to check in TCL if valid x display has been set

From Dev

verify x509 certificate with openssl to be valid and signed by trusted CAs

From Dev

Conversion from string "X.X" to type 'Double' is not valid

From Dev

Check valid values of likert scales in R

From Dev

What constitutes a valid symbol (identifier) in R

From Dev

VirtualBox VERR_CR_X509_CPV_NOT_VALID_AT_TIME

From Dev

R - Is for(x in x) valid?

From Dev

Validation (@Valid) of two-dimensional list (List<List<X>>)

From Dev

What are valid characters in an X11 .conf Identifier name?

From Dev

Is this x86 assembly addressing method valid?

From Dev

How to get a list of valid X11 names for characters

From Dev

is x.x.0.x/24 a valid network ip address?

From Dev

Reverse for 'x' not found. 'x' is not a valid view function or pattern name

Related Related

  1. 1

    Why is `2 + x = 7` valid Haskell?

  2. 2

    Why is 'let x = 1' valid F# expression?

  3. 3

    Binding valid checkbox to enable button angularjs 1.2.x

  4. 4

    Converting a SSL Cert string into a valid X509_STORE_CTX

  5. 5

    Is Type(::x); valid?

  6. 6

    How to make a valid input for "xxd -r" in vim when removing a byte?

  7. 7

    'x64_mingw' is not a valid platform

  8. 8

    Check valid values of likert scales in R

  9. 9

    What constitutes a valid symbol (identifier) in R

  10. 10

    Merge r brings error "'by' must specify uniquely valid columns"

  11. 11

    int[] table = new int[10],x; is valid syntax?

  12. 12

    Why is {x:Null} no longer a valid value in a Style Setter in UWP?

  13. 13

    Valid syntax in both Python 2.x and 3.x for raising exception?

  14. 14

    C++: int x[+30] is a valid declaration?

  15. 15

    X509 certificate signed with bouncy castle is not valid

  16. 16

    SilverStripe dependent dropdown - x is not a valid option

  17. 17

    how to check in TCL if valid x display has been set

  18. 18

    verify x509 certificate with openssl to be valid and signed by trusted CAs

  19. 19

    Conversion from string "X.X" to type 'Double' is not valid

  20. 20

    Check valid values of likert scales in R

  21. 21

    What constitutes a valid symbol (identifier) in R

  22. 22

    VirtualBox VERR_CR_X509_CPV_NOT_VALID_AT_TIME

  23. 23

    R - Is for(x in x) valid?

  24. 24

    Validation (@Valid) of two-dimensional list (List<List<X>>)

  25. 25

    What are valid characters in an X11 .conf Identifier name?

  26. 26

    Is this x86 assembly addressing method valid?

  27. 27

    How to get a list of valid X11 names for characters

  28. 28

    is x.x.0.x/24 a valid network ip address?

  29. 29

    Reverse for 'x' not found. 'x' is not a valid view function or pattern name

HotTag

Archive