I solved 500 R-lang problems to learn R

Updated at: 29 January 2025

For my doctoral studies I decided to learn R lang for data analysis.

1. Print “Hello World”

message <- "hello world"
print(message)

2. Take input name and age from the user and display a message

n <- readline(prompt = "Enter your name: ")
a <- readline(prompt = "Enter your age: ")

print(paste0("Hello, ", n, "!", " You are ", a, " years old."))

paste() combines strings and adds spaces between, paste0() pastes without adding spaces.

3. Find the sum, mean and product of vector

vector = c(1, 5, 3, 6, 7, 15, 85, 22, 189)
sum(vector)
mean(vector)
prod(vector) # multiply all elements of the vector

I didn’t know what a product of a vector is 😮

4. Create numerical, and character vectors

vector = c(1, 5, 3, 6, 7, 15, 85, 22, 189)
vector = c("hello", "it's me", "Mike")

5. Access a specific element in a vector

vector = c("hello", "it's me", "Mike")
vector[3] # prints Mike

6. Calculate the median, skewness and kurtosis of a vector

vector = c(1, 5, 3, 6, 7, 15, 85, 22, 189)
median(vector)
skewness(vector)
kurtosis(vector)

7. Modify an element in a vector

vector[2] = 1 # assigns 1 to the element at position 2 

I found out that unlike in most programming languages, in R the arrays start at position 1, not 0

8. Get length of a vector

length(vector)

Autor: Michał KuczekMichał Kuczek

Founder of Biiird Studio, UX designer, business philosopher, psychologist, and conflict mediator.