Reading text files and getting a column’s average value : R Programming


Before doing anything interesting in R, we need to have some data to play with. I want to read in a list of End of Day prices for a company, and working out the average volume of that share traded.

This solution is going to require an account on to get access to the historical close prices of a share.


I’ve downloaded the close prices for Tesco and placed them in /users/nick/rdata
This is the code to read in the text file and calculate the average volume of shares traded:

> setwd(‘/users/nick/rdata’)  # set the working directory
> df <- read.csv(‘tesco.txt’)
> mean(df$X.vol)
[1] 22283443


Leave a Reply

Your email address will not be published. Required fields are marked *