dimanche 28 août 2016

R how to access a data frame in a return loop?

I am just trying to run a simple script that allows a user to randomly pull questions from a CSV file. A menu within a return loop gives the user various options of subsetting the questions. For whatever reason, I can't access the data frame within my return/if loops. I can't seem to figure out why. I've tried to globalize the data frame using <<-, but that didn't make a difference. Please see my code below:

data<-read.csv("/Users/Ivey/Desktop/InterviewQuestionRandomizer/QuestionSet.csv",header=TRUE,sep=",",encoding="UTF-8",comment.char="",stringsAsFactors = FALSE)

repeat
{
x<-menu(c("Random question from full set","Random question from IMPACT","Random question from BLAH","Select specific topic","Exit"),title="Interview Question Randomizer")

if(x==1){
  repeat
  {
    a<-sample(1:length(names(data)),1)
    a1<-sample(1:length(data[,a]),1)
    data[a,a1]
  fullset<-menu(c("Randomize","Return to menu"),"Options:")
  if (fullset==2){break}
  }
}

if(x==5){break}
}




Aucun commentaire:

Enregistrer un commentaire