vendredi 4 janvier 2019

I am receiving an 'unexpected { in {' message for my function - cannot see where this is or understand why the function won't work

I am hoping to group the variables from my data set into a pie chart. MY function is returning an error 'unexpected { in "{"'.

I would like the data to filter into 4 groups to then be plotted in a pie chart when the function is called.

I have tried opening and closing the while loop or moving the pie chart command.

data2<- read.csv("dataset1_r.csv", header = T, sep = ",")                 
head(data2)

mut1_func<- function(sex, age, mutation1, mutation2, exprs){
  a<-sex
  b<-age
  c<-mutation1
  d<-mutation2
  e<-exprs

  i<-1
  j<-200
  myresult2<-c()
  myresult3<-c()
  myresult4<-c()
  myresult5<-c()

  while (i<j){ ### while loop opens

    if (data2$mutation1[i] == 1 & data2$mutation2[i] == 1) {

      myresult2<-append(myresult2, data2$mutation1[i],data2$mutation2[i], i)

    } else if (data2$mutation1[i] == 1 & data2$mutation2[i] == 2) {

      myresult3<-append(myresult3, data2$mutation1[i], data2$mutation2[i], i)

    } else if (data2$mutation1[i] == 2 & data2$mutation2[i] == 1) {

      myresult4<-append(myresult4, data2$mutation1[i], data2$mutation2[i], i)

    } else (data2$mutation1[i] == 2 & data2$mutation2[i] == 2) {                            

      myresult5<-append(myresult5,data2$mutation1[i], data2$mutation2[i], i)

    }

     x<-c(myresult2, myresult3, myresult4, myresult5)
  labels<-c("Both", "Mutation 1", "Mutation 2", "Neither")
  pie(x, labels)

}

Aucun commentaire:

Enregistrer un commentaire