how to assign a variable in r in r

In R, you can assign a value to a variable using the assignment operator <- or =. The general syntax is:

main.r
variable_name <- value

# or

variable_name = value
52 chars
6 lines

Here's an example:

main.r
x <- 10
y = 5

# printing the values
x
y
41 chars
7 lines

Output:

main.r
[1] 10
[1] 5
13 chars
3 lines

In this example, we assigned the value 10 to the variable x using the <- operator, and the value 5 to y using the = operator. We then printed the values of x and y using their respective variable names.

related categories

gistlibby LogSnag