Thanks, it works great in getting all sets of numeric values together with the column names.
However, as a final step to complete the entire data frame, I still have something to be done. Right now the code that I have is,
input_file <- reactive({
if (is.null(input$dataset)) {
return("")
}
#read the input file
DATA <- readLines(input$dataset$datapath)
#get Macro details
Macroid <- vector(mode = "numeric", length = 0)
Macroid <- grep ( "Macro ID:", DATA, value = TRUE)
Macroid <- str_extract(Macroid, "(?<=:\t).+")
#get device details
DeviceName <- vector(mode = "numeric", length = 0)
DeviceName <- grep ( "Device ID/Name:", DATA, value = TRUE)
DeviceName <- str_extract(DeviceName, "(?<=:\t).+")
#get numerical values
StartPos <- str_which(DATA, "File Name:")
DataStartPos <- StartPos + 21
DataEndPos <- c(StartPos[2:length(StartPos)]-1, length(DATA))
VALUES <- vector(mode = "numeric", length = 0)
for (i in seq_along(DataStartPos)){
VALUES <- c(VALUES, DATA[DataStartPos[i]:DataEndPos[i]])
}
VALUES
VALUES <- as.data.frame(VALUES)
VALUES <- separate(VALUES, col = 1, c("Amps", "Volts", "Leakage"), sep = "\t")
SGP.df <- data.frame(Macroid, DeviceName)
Final.df <- merge(VALUES, SGP.df)
Final.df
})
The above code generates two data frames, i.e one for the META data and the other for numeric data. But when I merge, these two data frames, the output is somewhat messy compared to my expected result. In the above code I'm extracting values of the rows macroid, Device Name. Each of these header will have 3 values, as you can understand that each set of numeric values that we generate have one macro id and one Device id.
The expected output is,
First set of numeric data First macro id First Device Id
...................................... First macro id First Device Id
Last line of first set First macro id First Device Id
Secondset of numeric data Second macro id Second Device Id
...................................... Second macro id Second Device Id
Last line of first set Second macro id Second Device Id
Thirdset of numeric data Third macro id Third Device Id
...................................... Third macro id Third Device Id
Last line of first set Third macro id Third Device Id
But right now, with my above code, the data frame is generating one set of numeric data repeatedly for each device and macro headers.
I know some part of merging has to be improved than the one that I have now. Is there a better way to accomplish this.