Hi All,
I'm using read_CSV2 to read CSV files, with the same structures, but I would like to read them until a certain row (which varie according to the CSV):
row_2 <- 24
row_3 <- 21
info2 <- read_csv2(data2,
n_max=row_2,
skip=2)[ ,c(1:2, 12:14)] #select columns 1to2 and then 12 to 14
And create a macro variable to read the CSV file until the appropriate row.
But I don't know how to catch the right row number automatically.
Basically, the appropriate row would be the row number x where the 1st column contains the 1st 'Total' word. Or also another way would be to select all the rows until the next empty row ...
Does someone knows how I can select and get the row number ?
Unless the files are very large, I would read in the entire file and make a subset afterward.
DF <- read.csv2("/home/fjcc/R/Play/Dummy.csv")
DF
#> Name Value
#> 1 A 2
#> 2 B 4
#> 3 C 6
#> 4 Total 12
#> 5 F 4
#> 6 g 6
#> 7 q 23
#> 8 Total 33
Totals <- which(DF$Name == "Total")
DF2 <- DF[1:Totals[1], ]
DF2
#> Name Value
#> 1 A 2
#> 2 B 4
#> 3 C 6
#> 4 Total 12