CrumpLab / psyc7709_2019

Course website for PSYC 7709 - Using R for Reproducible Research (taught by Matt Crump 2019)
https://crumplab.github.io/psyc7709_2019/
1 stars 7 forks source link

Code error #8

Open mhorger opened 5 years ago

mhorger commented 5 years ago

I keep getting an error message on these lines of code and it doesn't matter if I delete the text- the error remains. It will stop a code from running even if it runs fine after I enter down a few lines. When I try to knit the page or build the website, it never completes the action and I believe it is because of this error. Has anyone else encountered this?

image

CrumpLab commented 5 years ago

Looks like a few different issues here.

  1. unless you have already defined bust earlier in your code, this will not work, as you are trying to assign bust into itself without creating it first.
    bust<-c(bust)

This would would work:

bust <- 1 # define bust
bust <- c(bust) # assign bust into itself
  1. Try something like this for the if/else statement
num <- 0
dollar <- 0

if (sample(1:6,1) == 3){
  num <- num+1
  dollar <- dollar +1
} else{
  num <- num+1  
  }

a. Your original code had if (sample(1:6) ==3). The sample(1:6) part produces a vector of 6 numbers (random orders of numbers from 1 to 6). You are then conducting a logical comparison between 6 numbers and one number, which will cause an error message. If you want to randomly pick a number between 1 to 6 and then test to see if it is a three try if( sample(1:6,1) ==3 ) b. I wasn't sure what you were trying to do on line 607...but if you were just trying to add 1 to the num and dollar variables, then my suggested code above does that.