Code
<- iris my_data
Steen Flammild Harsted
January 10, 2024
<-
<-
do?iris
to an object called my_data
iris
is available to you when you load R. It´s an inbuilt dataset. So it is available to you even though you cant find it in the Environment pane. Just type iris
.
my_data
c()
The c is short for concatenate, and means to link together.
This function combines values into a vector or list. 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 4c()
to create a sequence of numbers from 0 to 4 in steps of 2
seq()
Of course, such predictable operations can be done with ease in a more reliable way. We will use the function seq()
as an example. The output of this function is a sequence of numbers. The sequence of numbers is dictated by the arguments that you provide.
Read the arguments section on help page for seq()
Type ?seq()
in the console or type seq()
and pres F1 while the cursor stands on the on the letters.
sample()
sample()
, take a sample of 5 random numbers between 1 and 100replace
do? What is the default value?
mean()
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?c()
, take the mean of the numbers 5, 3, 1, and 10c(2, 4, 6, NA)
c(2, 4, 6, NA)
, disregarding NA
valuesRead about the na.rm
argument in the mean()
function. What is the default value?
na.rm
argument in many functions. It always defaults to FALSE. Discuss if this is a good idea? Is it different from other programs?
%>%
%>%
? (Pres CTRL+SHIFT+P and type pipe in the search field).tidyverse
Why? The %<%
is a part of the tidyverse, and is not included in Base R
Investigate the following functions that we may need later on in this course.
quantile()
rnorm()
median()
cumsum()
min()
max()
n()
set.seed()