I hear loops are best avoided in R.Is there a better way to do something like this perhaps using lapply, etc.?library(xlsx)files <- list.files(path=/tmp/data, pattern=*.xls, full.names=T, recursive=TRUE)for(i in 1:length(files)) {  df <- read.table(files[i], header=TRUE)  avgArea <- mean(df[df$Area>20,Area])  avgMean <- mean(df[df$Area>20,Mean])  fnNew <- paste(tools::file_path_sans_ext(files[i]), .xlsx, sep=)  wb <- createWorkbook(type=xlsx)  sheet  <- createSheet(wb, sheetName=data)  addDataFrame(df, sheet)  rows  <- createRow(sheet, rowIndex=nrow(df)+1)  cells <- createCell(rows, colIndex=1:4)  setCellValue(cells[[1,2]], Average)  setCellValue(cells[[1,3]], avgArea)  setCellValue(cells[[1,4]], avgMean)  saveWorkbook(wb, fnNew)}An example .xls can be found here 
R code to read table, perform calculations, and write excel
beginner;excel;r