I am using R to calculate the mean values of a column in a file like so:
R
file1 = read.table("x01")
mean(file1$V4)
However I have no experience building loops involving R, only with bash. How would I convert this into a loop that did this for every file in a folder and saved the output into one file with the file name and mean value as the 2 columns for each row? eg:
x01(or file1 if that is simpler) 23.4
x02 25.4
x03 10.4
etc
(Don't mind if the solution is bash and R or exclusively R) Many thanks for your help!
Current error from one of the solutions using bash and R:
Error in `[.data.frame`(read.table("PercentWindowConservedRanked_Lowest_cleanfor1000genomes_1000regions_x013", :
undefined columns selected
Calls: mean -> [ -> [.data.frame
Execution halted