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

Problem:

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 www.eoddata.com to get access to the historical close prices of a share.

Solution:

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

 

This entry was posted in Data Science, R Programming. Bookmark the permalink.

Leave a Reply

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