R Scripts Flashcards
Library(tidyverse)
called out database named tidyverse
View(msleep)
called out dataset known as msleep
?msleep
to know the description of the dataset
names(msleep)
to get the list of variables
msleep %>%
refer to msleep dataset
msleep %>%
rename(“converse”=”conservation”) %>%
View()
rename converse to conversation in msleep
msleep %>%
select(vore,name,everything()) %>%
View()
reorder the variable, have core column vore and name, followed by everything.
msleep %>%
select(vore,name,brainwt) %>%
View()
only want certain variables; vore, name, and brainwt.
msleep %>%
filter((order==”Carnivora”|order==”Primates”)& sleep_total>8) %>%
select(name,order,sleep_total) %>%
to filter and arrange, filter under the variables we want carnivora and primates and under sleep total we want more than 8 hours
arrange(-sleep_total) %>%
View()
arrange sleep total to descending order
mutate
changing the variable
msleep %>%
mutate(brainwt_in_grams=brainwt*1000) %>%
View()
we want to change braiwnt from kg to grams
drop_na(vore)
go to vore column and remove not available
mutate(brain_size=if_else(brainwt>0.01,”large”,”small”)) %>%
View()
change numeric to categorical
size_of_brain=msleep %>%
create a new file known as size of brain