I have a folder full of file.txt.
Each file rappresent a dataset
In this file there are different columns, but im focusing on the column Date
the file formatting is as follows
H,Data,Ora,VBatt(V),Liv,Tac,mS,pH,Rx,%air,Ta,Ta-m,Ta-M,WD,WS,WS-m,WS-R,WS-D,WS-T,Pi,Sbf,Ur,Ur-m,Ur-M,Pa,Pa-m,Pa-M,Rs,Rs-m,Rs-M,A2,A2-m,A2-M,A1,A1-m,A1-M,ET0,TD,TWB,Ch11,Ch11-m,Ch11-M,Ch12,Ch12-m,Ch12-M,Ch13,Ch13-m,Ch13-M,Ch14,Ch14-m,Ch14-M,Ch15,Ch15-m,Ch15-M,Ch16,Ch16-m,Ch16-M,Ch17,Ch17-m,Ch17-M,Ch18,Ch18-m,Ch18-M,#
R,16/07/2022,00:00,12.97,,,,,,,24.06,23.87,24.26,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,65.94,64.65,67.29,800.00,800.00,800.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,17.16,20.07,9981.51,9981.55,9981.55,9981.51,9981.55,9981.55,9981.51,9981.55,9981.55,9981.51,9981.55,9981.55,9981.51,9981.55,9981.55,9981.51,9981.55,9981.55,9981.51,9981.55,9981.55,9981.51,9981.55,9981.55,#
My code is this
#controllo se le librerie ci sono sennò scarico
if(!require(tidyverse)||!require(dplyr)||
!require(lubridate)||!require(readr)||
!require(tibble)||!require(tools)){
install.packages("tools")
install.packages("dplyr") #summarise
install.packages("readr") #read.csv
install.packages("tidyverse") #serve per dplyr
install.packages("lubridate") #estrarre il mese
install.packages("tibble")#per add_column e add_row
}
library(tidyverse)
library(dplyr)
library(readr)
library(lubridate)
library(tibble)
library(tools)
setwd("C:/Users/stirp/OneDrive/Desktop/buff")
listaBuff<-list.files(pattern ="^MM")
i<-1
indiceFileDaRinominare<-i;
while(i<length(listaBuff)){
fileMinore<-read.csv(listaBuff[i],skip = 6)
j<-i
while(j<length(listaBuff)){
fileDaConfrontare<-read.csv(listaBuff[j],skip=6)
if(fileDaConfrontare$Data[1]<fileMinore$Data[1]){
indiceFileDaRinominare<-j
}
j<-j+1
}
fileMinore<-rename(read.csv(listaBuff[indiceFileDaRinominare],skip=6)
,paste0(i,".txt"))
i<-i+1
}
im trying to order the file by changing their name in the folder but i am keep getting this error:
Error in read.table(file = file, header = header, sep = sep, quote = quote, :
more columns than column names
at the end of execution the txt files within the folder are renamed in ascending order from the txt with the smallest date to the largest