Hello, I am very new to R, and this is certainly and uber-newby question: I am trying to read a vector of numeric data that contains the log of daily DJI returns and simply plot a histogram of it. The data I have is in a text file format, on each line a number represents the log of the returns of one day. I have problems in reading this in a vector numeric format. If I try retr<- as.numeric(read.table("logDJI.TXT", header=FALSE, sep="", dec="." )); I get: " Error in as.double.default(read.table("logDJIm.TXT", header = FALSE, sep = "", : (list) object cannot be coerced to 'double'" and when I try to plot: plot(density(retr, width=.004), type="l", xlab="y", ylab="pdf"); I get: "Error in density(retr, width = 0.004) : argument 'x' must be numeric" If I try: retr<- as.data.frame(read.table("logDJI.TXT", header=FALSE, sep="", dec="." )); I get no reading or conversion error, but I get the same error when I try to plot as above. Can anyone help with this? Thank you in advance, Alex
Alex K wrote:> Hello, > > I am very new to R, and this is certainly and uber-newby question: > > I am trying to read a vector of numeric data that contains the log > of daily DJI returns and simply plot a histogram of it. > > The data I have is in a text file format, on each line a number > represents the log of the returns of one day. > > I have problems in reading this in a vector numeric format. > > If I try > > retr<- as.numeric(read.table("logDJI.TXT", header=FALSE, sep="", dec="." ));read.table() returns a data.frame, as the docs point out, but as.numeric expects a vector. Either extract the first (and only?) column or read the data using scan(), if there is really only one column. Uwe Ligges> I get: > " Error in as.double.default(read.table("logDJIm.TXT", header = FALSE, > sep = "", : > (list) object cannot be coerced to 'double'" > > and when I try to plot: > > plot(density(retr, width=.004), type="l", xlab="y", ylab="pdf"); > > I get: > > "Error in density(retr, width = 0.004) : argument 'x' must be numeric" > > If I try: > > retr<- as.data.frame(read.table("logDJI.TXT", header=FALSE, sep="", dec="." )); > > I get no reading or conversion error, but I get the same error when I > try to plot as above. > > Can anyone help with this? > > Thank you in advance, > Alex > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Hi Patrick, thank you for your reply, On 5/20/05, Patrick Burns <pburns at pburns.seanet.com> wrote:> Two minor points: > > 1) You surely have logarithmic returns rather than the log of (some > type of) returns. >Yes, obviously, my mistake.> 2) Once you get data suitable for a histogram, do: > > hist(retr) >I tried that but hist() also expects a numeric vector, and that's what I can't find out how to do: extracting the data in a suitable form from the file. On "retr;" I get : " V1 1 -9.483434e-04 2 1.817336e-03 3 0.000000e+00 4 1.081303e-02" and so on until 2527, which is the number of entries. Thank you again for your reply, Alex
BXC (Bendix Carstensen)
2005-May-20 20:35 UTC
[R] Reading Numeric Data -- Trivial Question
You (and the mailing list) would defintely benefit from cliking on: Help -> Manuals -> An introduction to R and spend a few hours in frot of R while reading that. Bendix ---------------------- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 bxc at steno.dk www.biostat.ku.dk/~bxc ----------------------> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Alex K > Sent: Friday, May 20, 2005 11:26 PM > To: r-help at stat.math.ethz.ch > Subject: Re: [R] Reading Numeric Data -- Trivial Question > > > On 5/20/05, Uwe Ligges <ligges at statistik.uni-dortmund.de> wrote: > > Alex K wrote: > > > > > Hello, > > > > > > I am very new to R, and this is certainly and uber-newby > > > question: > > > > > > I am trying to read a vector of numeric data that contains the > > > log of daily DJI returns and simply plot a histogram of it. > > > > > > The data I have is in a text file format, on each line > a number > > > represents the log of the returns of one day. > > > > > > I have problems in reading this in a vector numeric format. > > > > > > If I try > > > > > > retr<- as.numeric(read.table("logDJI.TXT", header=FALSE, sep="", > > > dec="." )); > > > > > > read.table() returns a data.frame, as the docs point out, but > > as.numeric expects a vector. > > > > Either extract the first (and only?) column or read the data using > > scan(), if there is really only one column. > > > > Uwe Ligges > > Hi Uwe, thank you for the reply. > > How do I extract only the colum? > > The text file looks like: > "-0.000948343416257784 > 0.00181733586025109 > 0 > 0.0108130251220595" > > except is has about 2200 entries (numbers) instead of just > four as above. > > Thank you again, > Alex > > > > > > > > > > I get: > > > " Error in as.double.default(read.table("logDJIm.TXT", header = > > > FALSE, sep = "", : > > > (list) object cannot be coerced to 'double'" > > > > > > and when I try to plot: > > > > > > plot(density(retr, width=.004), type="l", xlab="y", ylab="pdf"); > > > > > > I get: > > > > > > "Error in density(retr, width = 0.004) : argument 'x' must be > > > numeric" > > > > > > If I try: > > > > > > retr<- as.data.frame(read.table("logDJI.TXT", > header=FALSE, sep="", > > > dec="." )); > > > > > > I get no reading or conversion error, but I get the same > error when > > > I try to plot as above. > > > > > > Can anyone help with this? > > > > > > Thank you in advance, > > > Alex > > > > > > ______________________________________________ > > > R-help at stat.math.ethz.ch mailing list > > > https://stat.ethz.ch/mailman/listinfo/r-help > > > PLEASE do read the posting guide! > > > http://www.R-project.org/posting-guide.html > > > > > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read > the posting guide! http://www.R-project.org/posting-guide.html >