R basics Flashcards
How do you create a new working directory?
File -> New Project -> follow the instructions
How do you create a new R script?
File -> New File -> R script
Which tab do you use to use R as a calculator?
the console (bottom left)
say you type in a letter (say “s”). How can you see a list of functions starting with s? How do you get the function without having to type in its whole name?
press tab. Scroll down to relevant function. Press tab again to complete.
How can you round 1.44 to nearest whole number?
x
How can you find the mean of the numbers 1 to 10?
x
How can you add the numbers 1 to 10?
x
What function can you use to see a codes datatype? (e.g. numeric, double, long etc.)
class(1.56)…..this will give you numeric
I want to see if some code is an integer. How can I test this?
is.integer(10.2)….this will give false given the number is not an integer!
What is a good package for working with strings (text?)
library(stringr)
Using stringR - How does R tell you the output of something is a string?
It puts it in quotation marks -> e.g. would give output “foo”
Using stringR - How to take a word in capitals to lower case?
str_to_lower(“FOO”)
Using stringR - How to take a word in lower case to upper case?
str_to_upper(“foo”)
Using stringR- How to make the first words of each letter a capital?
str_to_title(“foo bar”) = “Foo Bar”.
Using stringR- How do you get the length of string?
str_length(“foo”)= “3”
Using stringR- How do you get the two left characters in the word “foo”? i.e. how do you get “fo” as an output?
Use str_sub(“foo”,1,2) which gives “fo”. to get the right, you would use str_sub(“foo”, 2, 3).