0

I am trying to change the format of a column in R, to the same format that is done in Excel by formatting it in the following way: enter image description here

I tried doing:

file1$Time <- as.POSIXct(file1$Time, "%H:%M:%S")

But I get the Error:

Error:$ operator is invalid for atomic vectors

Is there any other way for me to do this in R? I am currently formatting the column before it is uploaded to R, but I am trying to reduce the complexity by doing all the work in R.

Thanks!

My code:

  observeEvent(uploadedFile1, {
    updateSelectizeInput(session, 'uploadChannels1', choices = names(uploadedFile1))
  })
  observeEvent(uploadedFile2, {
    updateSelectizeInput(session, 'uploadChannels2', choices = names(uploadedFile2))
  })

  # Upload the CSV File 
  uploadedFile1 <- reactive({
    validate(need(input$file1, FALSE)) # This is like a better "if (is.null(input$file1)) return(NULL)"
    uf1 <- read.csv(input$file1$datapath)
  })

  uploadedFile2 <- reactive({
    validate(need(input$file2, FALSE)) # This is like a better "if (is.null(input$file2)) return(NULL)"
    uf2 <- read.csv(input$file2$datapath)
  })

  observeEvent(uploadedFile1(), {
    updateSelectizeInput(session, 'uploadChannels1', choices = names(uploadedFile1()))
  })
  observeEvent(uploadedFile2(), {
    updateSelectizeInput(session, 'uploadChannels2', choices = names(uploadedFile2()))
  })

  output$graph <- renderDygraph({


    # Clean up the loaded CSV File, convert Time column to a Time Object for Dygraph.
    uploadedFile1 <- uploadedFile1()
    uploadedFile2 <- uploadedFile2()

    uploadedFile1$Time <- as.POSIXct(strptime(uploadedFile1$Time,"%H:%M:%S"))
    uploadedFile2$Time <- as.POSIXct(strptime(uploadedFile2$Time,"%H:%M:%S"))

    uploadedFile1$ctime <- strptime(paste(uploadedFile1$Time), "%Y-%m-%d %H:%M:%S")
    uploadedFile2$ctime <- strptime(paste(uploadedFile2$Time), "%Y-%m-%d %H:%M:%S")

    # Update the SelectInput and store the value in component5 to be used in the graph.
    selectedInput1 <- input$uploadChannels1
    selectedInput2 <- input$uploadChannels2
    component5 <- uploadedFile1[, selectedInput1]
    component6 <- uploadedFile2[, selectedInput2]
    cbinded <- cbind(component5, component6)

        xts(cbinded, uploadedFile1$Time, uploadedFile2$Time)  %>% 
      dygraph()

    })

Here is the output of dput(head(file1))): enter image description here

Gary
  • 2,137
  • 3
  • 23
  • 41
  • [How to make a great R reproducible example?](http://stackoverflow.com/questions/5963269) – zx8754 Jan 08 '16 at 16:23
  • Can you post the output of `dput(head(file1))` please? Is `Time` a column in the dataframe (i.e. it's not the rownames or something odd)? – Phil Jan 08 '16 at 16:25
  • I just added it above... – Gary Jan 08 '16 at 18:17
  • I added my code that I am using to manipulate the data. I am using strptime on the uploadedFiles, but for some reason that only works when the file is already in the time format when it comes from the CSV upload. – Gary Jan 08 '16 at 19:47

0 Answers0