Assignments Flashcards
What happens if you do the following:
c(1,2,3,4) + c(5,15) ?
The second vector is recycled, so you get
6 17 8 19
What does the upward arrow do in Rstudio?
It gives the previous command
What does the tab do?
It gives suggestions when you start typing a name of a variable.
How do you change your working directory?
setwd(‘name’) sets the current working directory to the directory with that name.
How do you ask for help/info about a function?
Put a ‘?’ in front of it and remove the parentheses.
Example: ?file.exists for the file.exists() function.
How do you get the current working directory?
getwd()
How do you get a list of all the objects in the current workspace?
ls()
How do you get a list of the files in the current working directory?
list.files()
How do you create a new directory?
dir.create(‘name’)
How do you check if a file exists?
file.exists(‘name’)
How do you create a new filepath name that can be used across platforms?
file.path(‘a’, ‘b’)
How do you create a directory within a directory?
dir.create((‘nametop’, ‘namenested’), recursive = TRUE)
How do you get a sequence of the numbers 1 to 20, including 1 and 20?
1:20 or seq(1,20)
What happens when you use seq(x,y) with real numbers?
It gives the sequence from x to y (inclusive) with increments of 1. May never reach y
How do you get help/info about an operator like : ?
? :
So put the operator between back ‘s
How do you adjust the increments when creating a sequence of numbers from x to y?
seq(x,y, by = z)
With z the size of increment.
What command do you give if you want a sequence of 30 numbers between 5 and 10?
seq(5, 10, length=30)
What is the best way to get a sequence of numbers with the same length as a vector variable?
seq.along(variablename)
How do you get the length of a variable?
length(variable)
How do you create a vector of thirty zeros?
rep(0, times=30)
How do you create a vector that repeats the pattern 0 1 2 ten times?
rep(c(0,1,2), times = 10)
How do you create a vector with ten 0s, ten 1s and ten 2s?
rep(c(0,1,2), each=10)
What are the two types of vectors?
Atomic vectors and lists.
Atomatic vector
Vector that contains only one data type