Back
Close

Computing with Data

elgeish
33.5K views

Scalar Data Types

Scalar types include numeric, integer, logical, string, dates, and factors:

rm(list = ls()) # clears all variables
a = 3.2; b = 3 # double types
b
typeof(b) # function returns type of object
c = as.integer(b) # cast to integer type
c
typeof(c)
c = 3L # alternative to casting: L specifies integer
d = TRUE
d
e = as.numeric(d) # casting to numeric
e
f = "this is a string" # string
f
ls.str() # show variables and their types
# Factor variables assume values in a predefined set of possible values.
# The code below demonstrates the use of factors in R:
current.season = factor("summer",
levels = c("summer", "fall", "winter", "spring"),
ordered = TRUE) # ordered factor
current.season
levels(current.season) # display factor levels
my.eye.color = factor(
"brown",
levels = c("brown", "blue", "green"),
ordered = FALSE) # unordered factor
my.eye.color
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants