C1 Intro to R Programming for Data Science Flashcards

(16 cards)

1
Q

What function can be used to determine the data type in R?

A

class() function

The class() function returns the class of an R object, allowing you to determine its data type.

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

Which function checks if a value is an integer?

A

is.integer() function

The is.integer() function returns TRUE if the value is an integer, otherwise FALSE.

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

Which function checks if a value is numeric?

A

is.numeric() function

The is.numeric() function checks if the value is of a numeric type.

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

Which function checks if a value is a character?

A

is.character() function

The is.character() function returns TRUE if the value is of character type.

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

Which function checks if a value is logical?

A

is.logical() function

The is.logical() function returns TRUE if the value is of logical type.

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

How can you convert a value to an integer in R?

A

as.integer() function

The as.integer() function converts a value to an integer type.

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

How can you convert a value to numeric in R?

A

as.numeric() function

The as.numeric() function converts a value to numeric type.

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

How can you convert a value to character in R?

A

as.character() function

The as.character() function converts a value to character type.

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

How can you convert a value to logical in R?

A

as.logical() function

The as.logical() function converts a value to logical type.

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

Which R function saves a workspace to a .RData file?

A

Save the entire workspace to a file named “workspace.RData”

save.image(file = “workspace.RData”)

Use Case: This is useful for saving all objects in your environment, ensuring you can resume your work later without losing any data or variables.

Default Behavior: If no file name is specified, save.image() saves the workspace to a file named .RData in the current working directory.

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

How can you determine the data type of an object in R?

A

You can use the class() function and the is.integer(), is.numeric(), is.character(), and is.logical() functions to determine the data type.

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

How can you convert some data types to other data types in R?

A

You can convert some data types to other data types using the as.integer(), as.numeric(), as.character(), and as.logical() functions.

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

True or False

The words ‘True’ and ‘False’ are not recognized as boolean values

A

True

R only recognizes TRUE, FALSE, T and F as special values for true and false. That means all other spellings, including True and true, are not interpreted by R as logical values.

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

Logical Operations in R

A

You can do a variety of logical operations in R including:
Checking equivalence: 1 == 2
Checking non-equivalence: TRUE != FALSE
Greater than: 100 > 1
Greater than or equal to: 100 >= 1
Less than: 100 < 1
Less than or equal to: 100 <= 1

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

Checking NA in R

A

You can check if a value is NA by using the is.na() function, which returns TRUE or FALSE.
Check if NA: is.na(NA)
Check if not NA: !is.na(2)

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

How do you convert a vector into a factor?

A

The function factor() converts a vector into a factor, and creates a factor level for each unique element.

genre_vector <- c(“Comedy”, “Animation”, “Crime”, “Comedy”, “Animation”)

genre_vector

genre_factor <- as.factor(genre_vector)

levels(genre_factor)

‘Animation’ ‘Comedy’ ‘Crime’