Show me the code
answer_to_everything <- 42Steen Flammild Harsted
August 17, 2025
You can download the course slides for this section here
Together in groups of two or three explain the following to each other:
2+2in the console and the script?
<-<- do?42 to an object called answer_to_everythinganswer_to_everything in the console
c()The c is short for concatenate, and means to link together.
This function combines values into a vector. For now you can think of a vector as a sequence of values. The values are seperated by a ,
c() to create a sequence of numbers from 0 to 4
my_sequenceRemember <-
sample()sample() to take a sample of 3 random values from my_sequencereplace do? What is the default value?
sample() to take a sample of 10 random values from my_sequencemean()Another function we can use is mean(). This function gives you the mean value of a sequence of numbers. Read the arguments section of the help page for mean()
mean() function require?my_sequencec(2, 4, 6, NA)c(2, 4, 6, NA), disregarding NA valuesRead about the na.rm argument in the mean() function.
Use F1 or ?mean
What is the default value?
na.rm argument in many functions. It always defaults to FALSE.
|>|> ? (Pres CTRL+SHIFT+P and type pipe in the search field).my_sequence.
Investigate the following functions that we may need later on in this course.
quantile()rnorm()median()cumsum()min()max()n()set.seed()