'How can I combine multiple Excel files and skip the first 6 rows of each file in R?
I have 103 .xlsx files in one folder with one sheet each. I want to combine them in one file via R and skip the first 6 rows of each file (junk information). Have tried different approaches but nothing worked.
rm(list = ls())
library(readxl)
library(tidyr)
library(tidyverse)
path = "X:/....."
setwd(path)
my_files <- list.files(pattern = "*.xlsx")
my_files
age = lapply(my_files, function(i){
x = read_excel(i, sheet=1)
x$file = i
x
})
age
I get this error message:
" New names:
- `` -> ...3
- `` -> ...4
- `` -> ...5
- `` -> ...6
- `` -> ...7
- ... and 20 more problems"
Solution 1:[1]
files = list.files(pattern = "*.xlsx")
df = list()
for (i in files){
df = append(df, list(as.data.frame(read_excel(i))))
}
df2 = data.frame()
for(i in 1:length(df)){
df2 = rbind.data.frame(df2,df[[i]][-c(1:6),])
}
Hi i have tested this on my dummy dataset. This code is working.It might help
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yagami_Light |
