In R, variables are created by assigning a value:
x <- 10
y = "R Language"Both forms work, but <- is the standard style in R.
Variable names:
. (dot)valid_name <- 100
.Valid <- "okay"
_invalid <- "not allowed"Variables can hold any type and change later:
You can reassign values at any point in a script:
temp <- 98.6
temp <- 37 # changes the value and typex <- 5 # global
myFunc <- function() {
x <- 10 # local
print(x)
}
myFunc()
print(x)The function prints 10, while the global x remains 5.
total_score instead of x)mean or sum<- for consistency with R style guidesAsk the AI if you need help understanding or want to dive deeper in any topic