Updated Dataset:
DateTime Object.Name Object.Value
6/22/2017 21:11 DaHum Normal
6/22/2017 12:59 DaHum Alarm
6/16/2017 18:48 DaHum Normal
6/16/2017 14:33 DaHum Alarm
6/15/2017 18:46 DaHum Normal
7/28/2017 8:00 ZON-1 58.56
7/28/2017 8:00 MA-H 51.66
7/28/2017 8:00 ZON-2 72.00
7/28/2017 8:00 ZON-4 70.00
7/28/2017 8:00 ZON-3 72.00
7/28/2017 7:45 PH 0.00
7/28/2017 7:45 OA 79.50
7/28/2017 7:45 SP 50.00
7/28/2017 7:45 ZON-1 32.47
7/28/2017 7:45 ZON-3 70.00
7/28/2017 7:45 CC 55.81
Hi I have dataframe in the below format:
I need to convert all the values under Object_Name
to column names. The Object_Names have duplicate values, i.e the same Name is repeated with different timestamp.
The data type of Object_Value
is alphanumeric, so when passed in R, it either takes as a Factor or a Character
Hence based on timestamp, I need to convert all the Object_Name row values to column name
Date Time Object_Name Object_Value
7/28/2017 08:00 A1 58.56
7/28/2017 08:00 A2 51.66
.
.
.
7/28/2017 08:30 A1 60.2
7/28/2017 08:30 A2 65.2
.
.
7/30/2017 08:30 B1 On
7/30/2017 09:30 B1 Off
I need the output
as below:
Date Time A1 A2 B1
7/28/2017 08:00 58.5 51.6 -
7/28/2017 08:30 60.2 65.2 -
7/30/2017 08:30 - - On
7/30/2017 09:30 - - Off
Code so far:
JCI <- read.csv("JCIS2.csv",header = T, stringsAsFactors=FALSE)
JCI$Object.Value <- as.numeric(JCI$Object.Value)
library(reshape2)
JCI_Reshape <- dcast(JCI_Unique, Date...Time ~ Object.Name, value.var = "Object.Value", fun.aggregate = mean)