R basics Flashcards

1
Q

How do you create a new working directory?

A

File -> New Project -> follow the instructions

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

How do you create a new R script?

A

File -> New File -> R script

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

Which tab do you use to use R as a calculator?

A

the console (bottom left)

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

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?

A

press tab. Scroll down to relevant function. Press tab again to complete.

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

How can you round 1.44 to nearest whole number?

A

x

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

How can you find the mean of the numbers 1 to 10?

A

x

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

How can you add the numbers 1 to 10?

A

x

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

What function can you use to see a codes datatype? (e.g. numeric, double, long etc.)

A

class(1.56)…..this will give you numeric

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

I want to see if some code is an integer. How can I test this?

A

is.integer(10.2)….this will give false given the number is not an integer!

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

What is a good package for working with strings (text?)

A

library(stringr)

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

Using stringR - How does R tell you the output of something is a string?

A

It puts it in quotation marks -> e.g. would give output “foo”

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

Using stringR - How to take a word in capitals to lower case?

A

str_to_lower(“FOO”)

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

Using stringR - How to take a word in lower case to upper case?

A

str_to_upper(“foo”)

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

Using stringR- How to make the first words of each letter a capital?

A

str_to_title(“foo bar”) = “Foo Bar”.

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

Using stringR- How do you get the length of string?

A

str_length(“foo”)= “3”

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

Using stringR- How do you get the two left characters in the word “foo”? i.e. how do you get “fo” as an output?

A

Use str_sub(“foo”,1,2) which gives “fo”. to get the right, you would use str_sub(“foo”, 2, 3).

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

Using stringR- How can you concatenate in R?

A

use str_c(“foo”, “bar”, sep= “ “) to get “foo bar”.

18
Q

Using stringR- can you put one function inside another?

A

YES! str_to_upper(str_c(“foo”, “bar”)) gives “FOOBAR”!

19
Q

What characters show how to allocate a function?

A
20
Q

Functions- assign a and b 1 and 2 respectively then add them to make c.

A

a

21
Q

Functions- assign a and b “George” and “Pugh” respectively then concatante using stringr

A

a

22
Q

Whats the best function for working with dates?

A

lubridate

23
Q

Lubridate- how to convert excel date format (e.g. 17498) to a proper date?

A

as_date(17498) = “2017-11-28”)

24
Q

Lubridate - how to get current date and time

A

now() function

25
Q

Lubridate- how to get todays date?

A

today() function

26
Q

Lubridate- how can you get information on todays date (e.g. month, year, quarter etc).

A

1) date_today

27
Q

Lubridate- how to convert your dates to the most common format (i.e. 2018-01-01).

A

use dmy() function: e.g. dmy(“01 January 2018”) would convert to 2018-01-01 which is the universal function.

28
Q

Lubridate- I have a date but want to add one month- how do I do this?

A

jan01

29
Q

What are logical data types?

A

True, false and NA (NA not sure which one it is)

30
Q

Logical data- if 1 < 2, how do I print “1 is less than 2” in the console?

A

if(1<2) { print(“1 is less than 2”) }. This will print in bottom left hand corner.

31
Q

Logical data- if 2 words are the same, how do I print “Equality found”

A

word1

32
Q

Logical data - how to print FALSE FALSE TRUE to search for NA’s if you have a vector of (“a”, “b”, NA)

A

vector_NA

33
Q

Vectors- how to produce 5 a’s in a row?

A

rep(“a”,5)

34
Q

Vectors- how to get the sequence 1 3 5 7 9?

A

seq.int(1,10,2)

35
Q

Tables- how can you get the iris dataset in R?

A

Just code in “iris”

36
Q

Tables- How can you get a table to come up in R without it appearing in a horrible format in the console?

A

Type in….. View(iris)

37
Q

Tables -How can you see the top and bottom 5 entries in a table?

A

Use head() and tail()

38
Q

Tables- how can you see the column names in a table?

A

colnames(iris)

39
Q

Tables- what packages are good for getting excel/csv files into R?

A

readr and readxl (cheat sheets available on github).

40
Q

Table- How can you change the format of a date column in R?

A

Use drop down in table viewer to make sure column is highlighted as a date. Use lubirdate to change it!