R Studio Flashcards

(16 cards)

1
Q

What is an object in R?

A

An object is anything created in R, they store data or results for later use.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

What does the q() function do?

A

quits an R session. When used, R asks if you want to save the workspace image.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a function in R?

A

A function performs an action in R, such as calculating, transforming, or analyzing data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the assignment operator in R?

A

<- assigns values to objects.

Example: x <- 2 stores the value 2 in the object x.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a script in RStudio?

A

A script is a text file containing R commands. You can save it as .R and run (source) it later.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What command shows the current working directory?

A

getwd()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What command sets a new working directory?

A

setwd()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you combine values into a vector?

A

Use c()

colors <- c( “red”, “blue”, “green”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you create a sequence of numbers?

A

Use the : operator

1:5 1, 2, 3, 4, 5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you repeat a value or sequence in R?

A

Use the rep() function

rep(3, 4) 3 3 3 3

rep(1:3, 2) 1 2 3 1 2 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you select an element from a vector?

A

Use square brackets []

x <- c (5, 10, 15)

x[2] 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you select multiple elements from a vector?

A

Use c() inside brackets.

x <- c (5, 10, 15)

x [c(1,3)] 5 15

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you exclude elements from a vector?

A

Use negative indices

x <- 5:10

x[-2] 5 7 8 9 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does vectorized arithmetic mean?

A

Operations apply element-by-element across a vector

x <- 1:4
x + 2 3 4 5 6
x * 2 2 4 6 8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you do element-wise operations on two vectors?

A

Operations match elements in the same position

a <- c(1,2,3)
b <- c(10,20,30)

a + b 11 22 33

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you take a square root in R?