I would like to import multiple ascii text files with selected rows in a one shot and I want to add file name as an ID number (variable) and then format the data as required (see the image below)
setwd("working_dir")
library(data.table)
library(WriteXLS)
files <- list.files(pattern=".*.asc")
file.list <- sapply(files, function(x)read.csv(x,header=F,skip = 10,nrows=10,stringsAsFactors=F), simplify=FALSE)
df1 <- rbindlist(file.list, idcol="id")[, id := substr(id,1,7)]
WriteXLS(df1,"all_1.xls",Encoding = "latin1")
this is how df1 data frame looks like and i want to format/select only the required data as shown in my deired result picture
df1 <-structure(list(id = c("9864707", "9864707", "9864707", "9864707",
"9864707", "9864707", "9864707", "9864707", "9864707", "9864707",
"9864708", "9864708", "9864708", "9864708", "9864708", "9864708",
"9864708", "9864708", "9864708", "9864708"), V1 = c("Mean irradiance (kW/m²)",
"1.000", "Pmax", "267.793", "Module voltage", "Voc", "37.552",
"Module current", "Isc", "9.217", "Mean irradiance (kW/m²)",
"1.000", "Pmax", "268.211", "Module voltage", "Voc", "38.234",
"Module current", "Isc", "9.181"), V2 = c("Cell efficiency (%)",
"18.4", "Module temperature (°C)", "22.2", "", "Vmp", "31.159",
"", "Imp", "8.735", "Cell efficiency (%)", "18.4", "Module temperature (°C)",
"22.2", "", "Vmp", "31.208", "", "Imp", "8.735"), V3 = c("Module efficiency (%)",
"16.4", "", "", "", "Series resistance", "0.1256", "", "Shunt resistance",
"191.7", "Module efficiency (%)", "16.5", "", "", "", "Series resistance",
"0.3718", "", "Shunt resistance", "309.8"), V4 = c("Fill factor (%)",
"77.4", "", "", "", "", "", "", "", "", "Fill factor (%)", "76.4",
"", "", "", "", "", "", "", "")), .Names = c("id", "V1", "V2",
"V3", "V4"), row.names = c(NA, -20L), class = c("data.table",
"data.frame"), .internal.selfref = <pointer: 0x000000000a7b0788>)