Usage of local variables

前端 未结 2 1627
北荒
北荒 2020-12-17 21:01

Problem:

How to define local variables within a scope in a r-code.

Example:

In C++ the following example defines a

相关标签:
2条回答
  • 2020-12-17 21:25

    You can create a new environment where your variable can be defined; this is how the local scope within a function is defined.

    You can read more about this here

    check the help for environment as well i.e. type in your R console ?environment

    0 讨论(0)
  • 2020-12-17 21:39

    Use local. Using your example:

    local({ 
         V1 = c(1,2,3);
         V2 = c(1,2,3);
         P = inner_product(V1, V2);
         print(P);
    })
    # the variable V1, V2, P are undefined here!
    
    0 讨论(0)
提交回复
热议问题