Thank you for your reply!
I've tried what you suggested, please bear with me since I'm just getting to understand the %>% function.
Trying to adapt what you suggested I got the below:
> #MERGING BOTH DF INTO ONE.
> df1 <- data.frame(merge(eta_dt,etd_dt, all = TRUE))
> df1 %>%
+ mutate(df1$ETA = dmy_hm(df1$ETA))
Error: unexpected '=' in:
"df1 %>%
mutate(df1$ETA ="
Please find below my full script at the moment, sorry but I have notes in them. I tried using %>% function as you can see to change the column names but could not make it work so had to try another approach.
library(tidyverse)
library(ggplot2)
library(lubridate)
### LOADING DATA
eta_dt <- read_csv(choose.files())
etd_dt <- read_csv(choose.files())
#ett_dt <- read_csv(choose.files())
#ENSURE THEY ARE DF
eta_dt <- data.frame(eta_dt)
etd_dt <- data.frame(etd_dt)
#ett_dt <- data.frame(ett_dt)
class(eta_dt)
#SETTING SHIPMENT ID AS FACTORS for rbind (not sure if necessary)
eta_dt$Shipment.ID <- as.factor(eta_dt$Shipment.ID)
etd_dt$Shipment.ID <- as.factor(etd_dt$Shipment.ID)
#### DATA HAS COLS WITH SAME name FIXING THAT FOR EACH DT SET
#### renaming columns, was trying to use the RENAME FUNCTION but found in stackflow that could use "select" function. pipe does seem
#to work but doesn't save it, it only works
#when pipped, forum submission query made.
#etd_dt %>% rename(
# Shipment.Kind = Type_1,
# Container.Type = Type_2
#)
#class(etd_dt)
colnames(eta_dt)[29] <- 'Shipment.Kind'
colnames(eta_dt)[215] <- 'Container.Type'
colnames(eta_dt[29])
colnames(eta_dt)[215]
######Found below example, of using base R code for this. Another way of doing above.
#names(etd_dt)[names(etd_dt) == 'Type_1'] <- 'Shipment.Kind'
#names(etd_dt)[names(etd_dt) == 'Type_2'] <- 'Container.Type'
#colnames(etd_dt)[29]
#colnames(etd_dt)[215]
#This code pretty much does the following:
#1. names(df) looks into all the names in the df
#2. [names(df) == old.var.name] extracts the variable name you want to check
#3. <- 'new.var.name' assigns the new variable name.
str(eta_dt)
str(etd_dt)
#MERGING BOTH DF INTO ONE.
df1 <- data.frame(merge(eta_dt,etd_dt, all = TRUE))
#####################################################################################################################################
############################################ DATES MGMT #############################################################################
#####################################################################################################################################
df1 %>%
mutate(df1$ETA = dmy_hm(df1$ETA))
#####################################################################################################################################
############################################ DATES MGMT #############################################################################
#####################################################################################################################################
####################################################################################################################################
####################################################################################################################################
################################# CORRECTING DATA TYPES FOR DF1 TO PROCEED TO ANALYSIS ############################################
####################################################################################################################################
####################################################################################################################################
df1$Consol.ID <- as.factor(df1$Consol.ID)
df1$Shipment.ID <- as.factor(df1$Shipment.ID)
df1$Trans. <- as.factor(df1$Trans.)
df1$Cont. <- as.factor(df1$Cont.)
df1$Origin <- as.factor(df1$Origin)
df1$Dest. <- as.factor(df1$Dest.)
df1$Creating.User.Login <- as.factor(df1$Creating.User.Login)
Thank you for your time once again and thank you so much for assisting me in this learning process.
Best regards,
LF.