R - Lab 1 Flashcards

1
Q

text

A

Makes a comment.

Use comments frequently

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

3+5

A

Addition

8

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

2*3

A

Multiplication

6

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

4^2

A

Exponents

16

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

exp(1.5)

A

Calculates e to the 1.5 power

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

x=exp(1.5)

A

Makes variable ‘x’ equal to exp(1.5)

Doesn’t report anything

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

Recalling a variable

A

Type the variable
Ex: If x=exp(1.5)
x
4.481689

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

log(x)

A

Natural log of x

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

What happens if you write incomplete code?
Example:
x=exp(1.5

A

R will give a ‘+’ on the next line

- Either finish (type ‘)’ ) or press escape

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

How to scroll through history of commands?

A

Up and down arrows

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

How to bring up the help file for a command?

A

help([command])

So:
help(exp)

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

How to search for functions that include a certain word?

A

??’[text]’

??’exponentiate’

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

What letter must you put in front of parenthesis to create a vector (list of values)?

A

c

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

Example vector

A

x=c(4,5,6)

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

In vectors:

x[2]

A

Tells us the 2nd value of x.

If
x=c(4,5,6)
Then
x[2]= 5

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

What will exp(x) do if x contains a vector?

A

Calculate exp to the power of each value in x; return a list of scalars.

17
Q

What is a function?

A

Any command that takes arguments (in parentheses) and returns results based on a calculation.

18
Q

Example functions

A

log(x)

exp(x)

19
Q

What is a matrix?

A

A block of numbers with multiple rows and columns.

20
Q

How to create a matrix in R?

A
  1. Create at least two vectors.
    Ex:
    year=c(1800,1850,1900,1950)
    carbon=c(8,54,534,1630)
  2. Assign the data.frame() function to a variable.
    Ex:
    datum=data.frame(Year=year,Carbon=carbon)
  3. View by typing the variable
    Ex:
    datum shows the matrix
    datum[2] shows just the second column
21
Q

How do you show the data of just a column AS a column? How do you show the data of a column AS a row of text?

A

Column
datum[2]

Row of text
datum$Carbon

22
Q

What are the three easy summaries/analyses of data?

A

summary(datum)
- provides mean and quartile

head(datum)
[SAYS ‘checks that data was imported properly’ but seems like python head()]

names(datum)
Gives you attributes of data or other objects

23
Q

How do you make a simple plot?

A

plot(datum)

X-axis is the first variable in the matrix

24
Q

plot(Carbon~Year) doesn’t work. Why?

A

‘Carbon’ and ‘Year’ don’t exist outside the datum data.frame

25
Q

If you can’t reference the column names outside of the dataframe, how do you plot it?

A

plot(Carbon~Year,data=datum)

26
Q

Another way of doing plots

A

plot(x=datum$Year,y=datum$Carbon)

27
Q

How do you clear console, and does it eliminate objects you’ve created?

A

“Edit” option in top left > “Clear Console”

This does NOT eliminate the objects you created.

28
Q

How do you list all the objects in memory?

A

ls()

Think “list”

29
Q

How do you remove objects in memory?

A

rm()

30
Q

How do you load a package? What’s a prerequisite?

A

Pre: Package is installed. Giggidy.

Ex:
library(nlme)

31
Q

What is the code to load data into R?

A

datum=read.csv(file.choose())