I'm slightly confused by if you want to just print the 6 lines or store them and if you want to keep the remainder of the csv files or not. Let's say all you want is to print the 6 lines, then, assuming you know the file names you can do this with
print(read.csv(filename, nlines = 6))
And repeat for each file. Alternatively if you want to save each file then you could do
f1 <- read.csv(filename, nlines = 6)
Repeat for each and use print(head)
.
Alternatively using your method but fixing the overwrite problem:
library(xlsx)
for(i in 1:7)
assign(paste0("d",i), read.csv(file.choose(),header=T))
lapply(list(d1,d2,d3,d4,d5,d6,d7),head)
The use of assign
dynamically assigns names so that each is unique and doesn't overwrite each other, which I think is what you were aiming for. This isn't very 'elegant' though but fits with your chosen method