test 1 Flashcards
== means
“are the 2 things equal to each other?” or “is equal to”
!= means
is not equal to
> = means
is greater than or equal to
<= means
is less than or equal to
> means
is greater than
< means
is less than
logical operators in R- what means true and what means false?
true = 1
false = 0
(what the computer tells you when you ask it)
what are the ways I can ask this question and what type of responses would I get?
are any of the x greater than or equal to 40 AND less than 60?
x >= 40 & x <60 - you would get a string of statements that say “true” or “false” for each element in the vector
sum ( x >= 40 & x < 60) - adding the sum command would count how many of them are true
which ( x >= 40 & x < 60) - tells you which element is true to the statement don’t use much but still useful
what does $ do?
- grabs out a column from what you defined
- can use it to add a new column too
how to add another column to a data frame?
df.name$column <- c(…)
if you have already defined “seedlings,” how can you extract the number of times the count “0” was observed?
sum(seedlings == 0)
sum gives the count, otherwise would just give the elements
if you defined seedlings, and now you want to see how many times each count occurred, what would you do?
df.seedlings <- data.frame (seedlings = c(0,1,2,3,4,5), freq = c(sum(seedlings==0), sum(seedlings ==1), sum(seedlings==2), sum(seedlings==3), sum(seedlings==4), sum(seedlings==5)))
first create data frame and then create 2 columns. one for the seedlings and one for the frequency. and then use the sum command to count how many seedlings were equal to 1, 2, 3, 4, and 5
you’ve defined x, now you want to get the 3rd and 4th elements of x, how?
all but the 3rd and 4th elements?
x[c(3,4)]
have to use both the square brackets and the vector ones
x[-c(3,4)]
put the negative outside of the c
defined x, how to get only even numbers out?
to get the elements in reverse?
x[seq(2, length(x), by=2)]
x[10:1]
if x is defined, how to get the sum of the first and last element if there are 10 elements? the product of second and ninth?
x[1] + x[10]
x[2] * x[9]