0

I have a dataset of locations and dates.I have to plot a bar graph of locations across dates. I tried the code below but got above error:argunets imply differing number of rows.my dataset contains around 25000 rows of data and 15 columns.will you help me with ploting a bar graph ??

I have tried this code:

for(i in 1:nrow(database)) {

    if(input$n1==as.integer(unique(sub(".*/.*/","",database$pickup_date[i]))) &&
     input$n2==as.integer((unique(sub("/.*/.*","",database$pickup_date[i]))))) {
    date_var<-sub("/2.*","",database$pickup_date[i])
    date_var<-sub("*./","",date_var)
    #print(date_var)
    #list<-unique(list(database$Pickup_name))
    #list
    count=count+1
    name[count]<-as.list(sub(database$Pickup_name[i]))

  }
  df1<-data.frame(name,date_array)
  bp1<-barplot(df1$name,names.arg = df1$date_array)
  }
 read.table(text='pickup_location   pickup_name

3/14/2016 mumbai 6/12/2016 mumbai 1/19/2016 mumbai 4/6/2016 mumbai 3/26/2016 mumbai 1/30/2016 mumbai 6/17/2016 mumbai 5/21/2016 mumbai 5/27/2016 mumbai 3/10/2016 mumbai 5/10/2016 mumbai 5/15/2016 mumbai 2/19/2016 mumbai 6/1/2016 mumbai 5/27/2016 pune 5/16/2016 pune 4/11/2016 pune 4/14/2016 pune 6/27/2016 pune 6/5/2016 pune 2/28/2016 pune 4/1/2016 pune 4/9/2016 pune 6/25/2016 nashik 6/3/2016 nashik 2/14/2016 nashik 2/27/2016 nashik 6/20/2016 nashik 6/13/2016 nashik 3/23/2016 nashik 5/17/2016 nashik 5/21/2016 nashik 5/10/2016 nashik 4/17/2016 nashik ')

goood0001
  • 9
  • 2
  • 2
    Perhaps `name[[count]] <- ...` instead of `name[count] <- ...`? Generally it's best to include a reproducible & minimal example including sample data and explain what you're trying to do. – Maurits Evers Jul 06 '18 at 03:32
  • 2
    `sub` is vectorized . You don't need a loop. Also, the `sub(database$Pickup_name[i]))` is without a pattern – akrun Jul 06 '18 at 03:33
  • Can you help me with ploting a bargraph of location across dates. – goood0001 Jul 06 '18 at 03:44
  • 1
    Please provide a small reproducible example as the other commenter requested – akrun Jul 06 '18 at 03:45
  • pickup_date Pickup_name 3/14/2016 mumbai 6/12/2016 mumbai 1/19/2016 mumbai 3/26/2016 mumbai 1/30/2016 mumbai 6/17/2016 mumbai 5/21/2016 mumbai 5/27/2016 mumbai 3/10/2016 mumbai 5/10/2016 mumbai 5/27/2016 pune 5/16/2016 pune 4/14/2016 pune 6/27/2016 pune 2/28/2016 pune 6/25/2016 pune 6/13/2016 nashik 3/23/2016 nashik 5/17/2016 nashik 5/21/2016 nashik 5/10/2016 nashik 4/17/2016 nashik 6/23/2016 nashik 5/27/2016 nashik – goood0001 Jul 06 '18 at 03:53
  • 1
    No data in comments, please, just edit the question and insert it there. One question per question, please. If you've resolved the issue with *"differing number of rows"*, then self-answer or just close/delete this question. Your request for plotting should really be a new question. – r2evans Jul 06 '18 at 03:54
  • can you help me for attaching a file or sending you the data – goood0001 Jul 06 '18 at 04:13
  • 1
    There are some good examples at: [reproducible questions](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), namely with `dput(head(x,n=10))` (or whatever size and/or selection of rows provides a complete example). Alternatively, just include a literal `read.table(text='...')` or `data.frame(a=c(1,2,3),...)` building command. – r2evans Jul 06 '18 at 04:45

0 Answers0