Copy and paste the following code to your R Studio platform or R version:

# Data types in R
# Integer
x <- 2L # the assignment operator, along with the Integer identifier
x
typeof(x) # to search for the type of x

# Double type (decimal point)
y <- 2.5
y
typeof(y)

# Complex
z <- 3 + 2i
z
typeof(z)

# Character
a <- “James”
a
typeof(a)

# Logical
# TRUE T
# FALSE F
q <- TRUE
q
typeof(q)

4 < 5
10 > 100
4 == 5

# Equal to: ==
# Not equal to: !=
# Greater than: > (=)
# Less than: < (=)
# Not: !
# Or: /
# And: &
# To check if it is true: isTrue(x)

result <- 4 < 5
result
typeof(result)

result2 <- !TRUE
result2 <- !(5 > 1)
result2

result | result2
result & result2

isTRUE(result2)
isTRUE(result)

# Using variables

A <- 10
B <- 5
C <- A + B
C
print(C)

var1 <- 2.5
var2 <- 4

result <- var1 / var2
result

answer <- sqrt(var2)
answer

greeting <- “Hello”
name <- “James”
message <- paste(greeting, name)
message

Posted by Dimitris

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s