OneBite.Dev - Coding blog in a bite size

declare a local variable in R

Code snippet on how to declare a local variable in R

x <- 3

This code declares a local variable, which is called ‘x’, and assigns it the numerical value of 3. The less-than symbol (or ‘arrow’) is used to assign a value to a variable in R, much like an equal sign (=) is used in other programming languages. In this example, the value 3 is assigned to the variable x. This means that the variable x can be used in other code, and will have the value of 3. As this is a local variable, it can only be used within the same code block (e.g. a function).

r