Consider the vectors:
What are their types?
What are their types?
Why are these different? Aren’t they all vectors?
00:30
What’s the average age?
What’s the average age?
How do we get the second element of conifer?
00:30
How do we get the second element of conifer?
Consider the dataframe:
How do we access the third row of my_df?
00:30
How do we access the third row of my_df?
How do we access the age in the third row of my_df?
00:30
How do we access the age in the third row of my_df?
You learned about some very important operators in Chapter 4:
> and <: greater than and less than>= and <=: greater than or equal to and less than or equal to== and !=: equal to and not equal to&: and|: or%in%: inRemember, we can use these operators to subset vectors and dataframes:
In ages, get all ages that are greater than 82
[1] NA 120 82
01:00
Remember, we can use these operators to subset vectors and dataframes:
In ages, get all ages that are greater than 82
Remember, we can use these operators to subset vectors and dataframes:
In ages, get all ages that are greater than 82
What’s going on with that NA? Try:
Remember, we can use these operators to subset vectors and dataframes:
In my_df, get all rows that are not conifers
names ages conifer
1 Western red cedar NA TRUE
2 Douglas-fir 120 TRUE
3 Pacific madrone 82 FALSE
01:00
Remember, we can use these operators to subset vectors and dataframes:
In my_df, get all rows that are not conifers
Remember, we can use these operators to subset vectors and dataframes:
In my_df, get all rows that are Pacific madrone
names ages conifer
1 Western red cedar NA TRUE
2 Douglas-fir 120 TRUE
3 Pacific madrone 82 FALSE
01:00
Remember, we can use these operators to subset vectors and dataframes:
In my_df, get all rows that are Pacific madrone
Remember, we can use these operators to subset vectors and dataframes:
In my_df, get all rows that are either Pacific madrone or Douglas-fir.
names ages conifer
1 Western red cedar NA TRUE
2 Douglas-fir 120 TRUE
3 Pacific madrone 82 FALSE
01:00
Remember, we can use these operators to subset vectors and dataframes:
In my_df, get all rows that are either Pacific madrone or Douglas-fir.
01:00
write.csv()write.csv()write.csv()write.csv()x and file are arguments supplied to the write.csv() function.
Functions in R fall into three categories:
read.csv(),pow() function do?pow() take?pow(5, 2) return?pow(v = 5, x = 2) return?pow("ten", "two") return?pow(x = 5, z = 2) return?02:00
pow() testpow() testpow() testpow() testConsider the following errors:
Error in x^v: non-numeric argument to binary operator
Error in pow(x = 5, z = 2): unused argument (z = 2)
What do/don’t you like about each error?
Which error message is better? Why?
02:00
pow() vs. new_pow()pow() vs. new_pow()pow() vs. new_pow()Write a function, called diff(), that takes the difference (subtracts) its first and second arguments.
05:00
A possible solution:
A possible solution with informative error messages:
Testing:
if, else