[R-SIG-Finance] zoo plotting - invalid 'ylim' value
Dirk Eddelbuettel
edd at debian.org
Thu Jun 18 05:08:33 CEST 2009
Spencer,
On 17 June 2009 at 20:43, spencerg wrote:
| I just lost perhaps a day's work due to that very problem: I
| couldn't get read.zoo to work, so I used read.table, which created
| factors, because some of my numeric columns included, ", NA", which got
| translated as a level " NA" (note this three character code with a space
| before the NA). Then I did "as.matrix" of the data.frame that I thought
| was numeric; the result was a zoo object with coredata of class
| character rather than numeric.
Very painful.
But that may be a good reminder that at the end of the day, almost all data
reading methods wrap around read.table --- i.e. read.csv "merely" sets the
separator option (and some others), read.zoo "merely" manages to set an index
option of appropriate type etc pp.
Why does this matter? Because read.table respect the (reasonably new) option
stringsAsFactors. From ?read.table:
read.table(file, header = FALSE, sep = "", quote = "\"'",
dec = ".", row.names, col.names,
as.is = !stringsAsFactors,
^^^^^^^^^^^^^^^^^
[...]
stringsAsFactors = default.stringsAsFactors(),
fileEncoding = "", encoding = "unknown")
[...]
stringsAsFactors: logical: should character vectors be converted to
factors? Note that this is overridden bu 'as.is' and
'colClasses', both of which allow finer control.
and from ?default.stringsAsFactors :
stringsAsFactors: logical: should character vectors be converted to
factors? The 'factory-fresh' default is 'TRUE', but this can
be changed by setting 'options(stringsAsFactors = FALSE)'.
It may be worthwhile to set this option in ~/.Rprofile
Hth, Dirk
--
Three out of two people have difficulties with fractions.
More information about the R-SIG-Finance
mailing list