Skip to Content

How to extract data from a csv table in R?

I have a csv file, and I want to extract the each column a as string so I can use it with getSymbols function from quantmod package.

The csv file goes as this:

AEGR,Aegerion Pharmaceuticals Inc
AKS,AK Steel Holding Corp
ALXA‎,Alexza Pharmaceuticals Inc
CCL‎,Carnival Corporation
CECO‎,Career Education Corp
CDXS‎,Codexis Inc

And I use this code to read the file:

data<-read.csv(file='CAPM/allquotes.csv',header=F)
symbols=gettext(data[,1])
symbol.names=gettext(data[,2])
getSymbols(symbols)

I get this error:

Error in download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  : cannot open URL 'http://chart.yahoo.com/table.csv?s=ALXA‎&a=0&b=01&c=2007&d=5&e=16&f=2012&g=d&q=q&y=0&z=ALXA‎&x=.csv'
In addition: Warning message:
In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  : cannot open: HTTP status was '404 Not Found'

When I enter the symbols one by one it works fine. I've also noticed that when I go to the end of the last line, the margins seem to corrupt. In the image you can see that values of 'symbols', the end of the line is a few more spaces to the right than it should be (you can see that because of the color of the initial parenthesis).