1.1.1 Flashcards
(42 cards)
What does the function library() do?
Loads packages
What function reads data into R?
read_csv(“”)
What does head() do?
Shows the first six rows of data by default
What does the function head(data, n = x) do?
Changes the number of rows displayed in head()
What is the function dim() used for?
Looking at how big the data is
What do the left and right number represent in the output of dim()?
Left = rows
Right = columns
What are observational units?
Individual entities on which data are collected (normally rows)
What are variables?
Any characteristic that varies between observational units (usually columns)
What does the dollar sign $ allow us to do?
Extract a specific variable from a dataframe
What is a vector?
Each variable in a dataframe
What are the square brackets [] used for?
Indexing (finding specific entries in the data)
What functions are used to find specific values in vectors and dataframes?
Use vector[entry] for vectors/single sequence of values
Use dataframe[rows, columns] for dataframes
What happens if we leave either rows or columns blank in the dataframe[rows, columns] function?
We will get out all of them
How can we identify a column using quotation marks?
dataframe[“column name”]
How can we combine multiple rows/columns using the combine function?
Dataframe[c(n1,n2), c(n3,n4)]
What function allows us to specify a sequence?
Colon from:to:
How can we combine the $ and [] function?
Dataframe$variable[row/column/vector]
What are conditions?
Conditions e.g. > or == allow us to access entries of data for which the condition is true
e.g.
somevalues[somevalues > 20]
starwars[starwars2$species == “Droid”, ]
What is the with() function and an example of using it?
A function that creates a container where variables of a data frame are available without the need to use $
e.g.
with(starwars2, starwars2[species == “Droid”, ]
What is data cleaning?
Identifying incorrect/incomplete/irrelevant data
Replacing/modifying/deleting them
How can we replace/overwrite/reassign parts of the data? Give an example
dataframe[row, column] <- “entry”
e.g.
starwars2[2,6] <- “Droid”
How can we assign selected entries to a new value? Give an example
Dataframe[dataframe$column==”entry”, “column name/number”] <- “entry”
e.g.
starwars2[starwars2$homeworld==”Naboo”, “species”] <- “Nabooian”
OR
starwars2$species[starwars2$homeworld==”Naboo”] <- “Nabooian”
How can we rewrite existing columns or add new columns in a dataframe, and what are 2 examples?
Dataframe$entry <- dataframe$entry / or * or + or – n
Dataframe$entry2 <- dataframe$entry / or * or + or – n
e.g. starwars2$height <- starwars2$height / 100 or starwars2$height2 <- starwars2$height / 100
How can we remove rows/columns from dataframes and what is an example?
dataframe <- dataframe[-row(s)/space, column(s)/space]
e.g.
starwars2[-c(35, 75),]