R Lecture Week3 Flashcards
whats wrong with this code and why
the single pipe operator is vectorised |
but the if statment is not vectoorised (it will only look at the first element that we get out)
so we should here use the double pipe || operator
we use || to be very clear that we are only taking in a single true or false
for if statements we should remeber to use && and ||
why with this ifelse function do we only use the | single
because ifelse is vectorised so we are wanting to return a respose for all 4 elements in the vector
1how to generate random numbers between 1 and 1000
2how to make sure you get the same random numbers
- sample(x = 1:1000, size = 100)
2. set.seed(5)
how to check if something is NOT na
!is.na(NA)
if( !is.na(as.numeric(input_miles))))
explain that line of code
- tries convert to numeric. if it can true. if it cant, NA.
then check value if its NA. run the code if its not NA