Noah Silverman
2012-Apr-06 17:13 UTC
[R] Converting data frame to its object results in matrix of strings
Hi, I have a rather large data frame (500 x 5000) that I want to convert to a proper xts object. I am able to properly generate an xts object with the correct time index. However, all of my numerical values are now strings. b <- as.xts(a[,2:dim(a)[2]], order.by=as.POSIXct(strptime(paste(a$Date), '%m/%d/%Y'))) My guess is that somewhere in the large data frame there are a few strings hiding that is causing the who thong to be converted to string. Is there some way to force the as.xts function to ignore the strings and keep everything numeric? Thanks! -- Noah Silverman UCLA Department of Statistics 8208 Math Sciences Building Los Angeles, CA 90095
R. Michael Weylandt
2012-Apr-06 20:10 UTC
[R] Converting data frame to its object results in matrix of strings
Try this: x <- xts(as.character(1:10), Sys.Date() + 0:9) storage.mode(x) <- "double" Michael On Fri, Apr 6, 2012 at 1:13 PM, Noah Silverman <noahsilverman at ucla.edu> wrote:> Hi, > > I have a rather large data frame (500 x 5000) that I want to convert to a proper xts object. > > I am able to properly generate an xts object with the correct time index. ?However, all of my numerical values are now strings. > > b <- as.xts(a[,2:dim(a)[2]], order.by=as.POSIXct(strptime(paste(a$Date), '%m/%d/%Y'))) > > My guess is that somewhere in the large data frame there are a few strings hiding that is causing the who thong to be converted to string. > > Is there some way to force the as.xts function to ignore the strings and keep everything numeric? > > > Thanks! > > > -- > Noah Silverman > UCLA Department of Statistics > 8208 Math Sciences Building > Los Angeles, CA 90095 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.