X <- list(height = 5.4, weight = 54)
cat("Printing objects: "); print(X)
print("Accessing individual elements:")
cat(sprintf("Your height is %s and your weight is %s\n", X$height, X$weight))
square <- function(x) {
return(x * x)
}
cat(sprintf("The square of 3 is %s\n", square(3)))
square <- function(x) {
x * x
}
square <- function(x) x * x
cube <- function(x = 5) x * x * x
cat(sprintf("Calling cube with 2 : %s\n", cube(2))
cat(sprintf("Calling cube : %s\n", cube())
powers <- function(x) list(x2 = x*x, x3 = x*x*x, x4 = x*x*x*x)
cat("Powers of 3: "); print(powers(3))
df <- data.frame(letters = letters[1:5], '#letter' = 1:5)
print(df$letters)
print(df$`#letter`)
m1 <- matrix(1:6, 2, 3)
m2 <- m1 %*% t(m1)
cat("Matrix product: "); print(m2)
a <- 1
b <<- 2
c = 3
4 -> d
5 ->> e