Quiz 7 Flashcards

1
Q

What is R?

A
  • programming language for statistical computing and data analysis
  • provides a wide range of statistical and graphical techniques and is highly extensible through packages
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is RStudio?

A
  • integrated development environment (IDE) for R
  • provides user-friendly interface for writing and running R code
  • includes a script editor, console, workspace, and many useful tools for data analysis
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is tidyverse?

A
  • collection of R packages designed for data science and data analysis
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a vector?

A
  • Fundamental data structure used to store a collection of values of the same data type
  • can be various types
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the various types of vectors?

A
  • numeric (ex numbers or decimals)
  • character (ex text)
  • logical (TRUE or FALSE)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What function is used to create a vector in R?

A

c () function (concatenate)
Ex. Colors

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

What function is used to create a vector in R?

A

c () function (concatenate)
Ex. Colors

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

What does R provide?

A
  • wide range of statistical and graphical techniques
  • is highly extensible through packages
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does tidyverse do?

A

Follows a consistent and intuitive syntax, making data manipulation and visualization easier

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

What are the components of the RStudio interface?

A
  • console window
  • scripting window
  • environment
  • plots
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can you save and reuse scripts for the future in R?

A
  • by writing in the scripting window
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are 2 ways to run a code in R?

A
  • type code in console window, press Enter
  • type in scripting window and press CTRL (CMD) + Enter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What would you type to assign variable x the number 3?

A

Either:
x <- 3
Or
x=3

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

How can you check the value of a variable (ex. x)?

A

Print(x) or just x

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

In R, what is the shortcut for <-?

A

ALT + - (hyphen)

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

How would you assign the name “John” to the variable ‘first’? How can you confirm it worked?

A

first <- “John”
print (first)

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

How would you concatenate string variables in R? (ex. put “first” and “last” names together)

A

Give string a name and identify the component variables
ex. full_name= paste0 (first, last)

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

What are the basic data types in R? Examples?

A
  • numeric (a <-23)
  • character (b <- “speech_data”)
  • logical (c <- TRUE)
  • complex (d <-2+3i)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What can you type in R to check the data type of a variable?

A

class (x)

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

How can you identify a function in R?

A

It’s anything that starts with a name/word followed by parentheses
Ex. Class(x)

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

How would you create a numeric vector in R?

A

numeric_vector <- c (1,2,3,4,5)
(‘c’ is for concatenate)

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

How would you create a character vector in R?

A

character_vector <- c (“apple”, “banana”, “cherry”)

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

How would you create a logical vector in R?

A

Logical_vector <- c (TRUE, FALSE)

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

What does it mean that vectors are indexed in R?

A

When you include a list of numeric, character or logical items, they are automatically numbered in that list
-ex. If you have colors <- c (“yellow”, “red”, “blue”), you can type colors [2] and it will display “red” because it was indexed as the second color

25
Q

How would you access the 3-5th elements of a vector?

A

ex. colors [3:5]

26
Q

How would you access the first and third elements of a vector?

A

ex. colors [ c (1,3) ]

27
Q

How would you exclude an element in a vector when using R?

A

ex. colors [-2]

28
Q

How do you complete an operation on an entire vector?

A

Type the name of the vector, then operation
ex. numbers *2 (will multiply all numbers in vector by 2)

29
Q

If you have a numbers vector with 1,3,5,7,9 and you entered numbers >3, what would be the result?
How would you display the actual values that are >3?

A

FALSE FALSE TRUE TRUE TRUE
numbers [numbers>3]

30
Q

How would you combine vectors in R?

A

ex all_numbers <- c (numbers, 2, 4, 6)

31
Q

How would you find the length of a vector (ex. Numbers)?

A

length (numbers)
*same for sum (numbers), mean (numbers), etc

32
Q

How to create a vector “days” with all the days of the week?

A

Days <- (“Sunday”, “Monday”, “Tuesday”, etc)

33
Q

How could you just display the weekdays from the “days” vector?

A

Type: days [c(-1, -7)]

34
Q

What happens if you have 5 values in a vector like num_1 and 5 other values in another vector like num_2 and you type num_1 + num_2 in R?

A

It would add the numbers that are indexed the same (ie. the first numbers in each vector, the second numbers in each vector, etc.—so the answer would have 5 different sums)

35
Q

What are data frames used for?

A

They store structured data in a tabular format, similar to a spreadsheet

36
Q

What do the rows and columns represent in a data frame?

A

Each row represents a single observation or record
Each column represents a variable or attribute

37
Q

What are data frame columns often used for?

A

You can use the column names to perform various operations on specific variables

38
Q

What are rows associated with in a data frame?

A
  • individual observations, cases or records
  • a unique index or identifier (typically starting from 1)
  • can access individual rows or subsets of rows based on conditions
39
Q

T/F Dataframes can only contain one type of data (ex. Numeric)

A

False—it can contain different types in the same structure, making it versatile for handling diverse data sets

40
Q

How would you create an empty data frame and why would you want to?

A

data.frame() (function with no arguments because brackets are empty)
Useful for initializing a data frame before adding data

41
Q

What is the function for loading data into R?

A
  1. library (tidyverse) (load library)
  2. ldt_data<- read_csv(ldt_data.csv) (read data)
  3. ldt_data (inspect data)
42
Q

What are the abbreviations for the numeric and character data types in a data frame?

A

Numeric= <dbl>
Character= <chr></chr></dbl>

43
Q

What function allows you to see an overview of all the columns, their data types, and ranges/levels of values?

A

summary()
ex. summary(ldt_data)

44
Q

What is the convention used to call an entire column of a data frame?

A

$

45
Q

How would you call all the rows in a particular column (ex. Freq)?

A

ldt_data$Freq

46
Q

How can you find the number of elements in a column (ex. Freq) from a data frame?

A

(number of elements= “length”)
length(ldt_data$Freq)

47
Q

How can you get the first 10 elements of the Freq column? The last 10?

A

ldt_data$Freq[1:10]
ldt_data$Freq[91:100]

48
Q

How would you change a value in a column from the data set (ex. the first value of the Freq column)?

A

ldt_data$Freq[1]<-99 (new, corrected value)

49
Q

How would you add 10 to each Freq value and save to a new vector (ex. Freq_plus_10)?

A

ldt_data$Freq_plus_10<-ldt_data$Freq+10
head (ldt_data) (this shows the first rows of a dataset)

50
Q

What do the head and tail functions do in R?

A

Read the first and last n rows of a dataset

51
Q

What are For Loops?

A
  • used to iterate over a sequence of elements and perform a set of operations repeatedly
  • a control structure that allows you to execute a block of code multiple times
52
Q

What are the 3 main components of a For Loop?

A
  1. initialization- specify a variable and set its initial value. This variable is used as a counter during the loop.
  2. iteration- after each iteration of the loop, the counter variable is updated according to a specified increment or decrement
  3. doesn’t specify a third?
53
Q

What is the basic structure that you would type for a For loop in R?

A

for (variable in sequence) {
type in code
}

54
Q

What do If Conditions allow you to do in R?

A

make decisions in your code by evaluating whether a certain condition is true or false

55
Q

What is an If Condition?

A

a control structure that allows you to execute specific code blocks based on whether a specified condition is true or false

56
Q

What is the basic structure of an If Condition?

A

if (condition) {
code to be executed if condition is true
}

57
Q

What is an example of an If Condition (ex. x=6 and if condition is to print “bigger” if x>5)

A

x<-6
if(x>5){
print(“bigger”)
}

58
Q

What can be added to an “if” condition if you want something to happen to values that don’t meet the condition?

A

an else statement
ex. x<-4
if(x>5){
print(“bigger”)
} else{
print(“not bigger”)
}

59
Q

What is an example of a combined For loop and If condition?

A

for(i in nums){
if(i>10){
print(i)
}
}