Previous: R Objects | Up: R Objects | Next: Data Structures |
R uses several classes of scalar values, from which it constructs larger data structures. R is highly class-dependent: certain operations will only work on certain types of values or certain types of data structures. We list the three basic types of scalar values here for your reference:
> log(3 * 4 * (2 + pi)) # Note that pi is a built-in constant, [1] 4.122270 # and log() the natural log function. > 2 > 3 # Basic logical operations, including >, [1] FALSE # <, >= (greater than or equals), # <= (less than or equals), == (exactly # equals), and != (not equals). > 3 >= 2 && 100 == 1000/10 # Advanced logical operations, including [1] TRUE # & (and), && (if and only if), | (or), # and || (either or).Note that Inf (infinity), -Inf (negative infinity), NA (missing value), and NaN (not a number) are special numeric values on which most math operations will fail. (Logical operations will work, however.)
> as.integer(TRUE) [1] 1 > as.integer(FALSE) [1] 0
> text <- "supercalafragilisticxpaladocious" > text [1] "supercalafragilisticxpaladocious"assigns the text string on the right-hand side of the <- to the named object in your workspace. Text strings are primarily used with data frames, described in the next section. R always returns character strings in quotes.