Values in R Programming Language
R has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples.
# Strings, which can be concatenated with paste0() or paste()
print(paste0("r", "lang"))
# Integers and floats
print(paste("1+1 =", 1+1))
print(paste("7.0/3.0 =", 7.0/3.0))
# Booleans, with logical operators as you'd expect
print(TRUE & FALSE)
print(TRUE | FALSE)
print(!TRUE)
To run the program, save it as values.R
and use the Rscript
command:
$ Rscript values.R
[1] "rlang"
[1] "1+1 = 2"
[1] "7.0/3.0 = 2.33333333333333"
[1] FALSE
[1] TRUE
[1] FALSE
In R, we typically use interactive sessions or run scripts directly, rather than compiling to binaries. The Rscript
command allows us to run R scripts from the command line.
R uses print()
or cat()
for output instead of a specific function like fmt.Println()
. String concatenation is typically done with paste()
or paste0()
rather than the +
operator.
For numeric operations, R behaves similarly to other languages, performing integer or floating-point arithmetic as appropriate.
Logical operations in R use &
(AND), |
(OR), and !
(NOT), similar to many other programming languages.