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:
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()
})