Programming Fundamentals/Variables/R: Difference between revisions

From Wikiversity
Jump to navigation Jump to search
Content deleted Content added
Creating
(No difference)

Revision as of 15:30, 23 November 2016

hello.r

print("Variables and Data Types", quote = FALSE)
i <- 12345
n <- 1.23456789012345
s <- "string"

print(paste("number:", i), quote = FALSE)
print(paste("number:", n), quote = FALSE)
print(paste("string: ", s), quote = FALSE)
print("", quote = FALSE)

print("Constants", quote = FALSE)
print("R doesn't support constants.", quote = FALSE)
print("", quote = FALSE)

print("Arithmetic Operators", quote = FALSE)
a <- 3
b <- 2
print(paste("a =", a), quote = FALSE)
print(paste("b =", b), quote = FALSE)
print(paste("a + b =", a + b), quote = FALSE)
print(paste("a - b =", a - b), quote = FALSE)
print(paste("a * b =", a * b), quote = FALSE)
print(paste("a / b =", a / b), quote = FALSE)
print("", quote = FALSE)

print("Assignment Operators", quote = FALSE)
a <- a + b
print(paste("a <- a + b is", a), quote = FALSE)
a <- a - b
print(paste("a <- a - b is", a), quote = FALSE)
a <- a * b
print(paste("a <- a * b is", a), quote = FALSE)
a <- a / b
print(paste("a <- a / b is", a), quote = FALSE)
print("", quote = FALSE)

print("String Concatenation", quote = FALSE)
s1 = "Hello"
s2 = "world"
print(paste(s1, " ", s2, "!", sep = ""), quote = FALSE)
print("", quote = FALSE)

print("User Input", quote = FALSE)
name <- readline("What is your name? ")
print(paste("Hello ", name, "!", sep = ""), quote = FALSE)

Try It

Copy and paste the code above into one of the following free online development environments or use your own R compiler / interpreter / IDE.

See Also