Make this process more CPU intensive and less memory intensive.

This question is a continuation of the Number of days in a year .

I did what Dirk suggested with a huge data.frame. My commands look like this:

dateSeq <- function(df) {
  res <- seq(as.Date(df["begin"]), as.Date(df["end"]), by = "1 day")
  format(res, "%Y")
}

dataFrame$seq <- apply(dataFrame, 1, dateSeq)
dataFrame_years <- do.call("c", dataFrame[["seq"]])

rm(dataFrame)
gc()
gc()

dataFrame_tab <- table(dataFrame_years)

Now these commands fill my 8 gigabyte RAM and 2 GB. At the same time, my processor is bored, having a processor load of perhaps 15%.

In addition, it takes my computer age to fulfill my "desires." Can I transfer some of the work to the CPU and free up my Ram a bit?

+3
source share
1 answer

In fact, this decision is an unsolicited hungry memory. Try the following:

begin <- as.POSIXlt("2007-05-20", tz = "GMT")
end <- as.POSIXlt("2010-06-13", tz = "GMT")

year <- seq(begin$year, end$year) + 1900
year.begin <- as.POSIXlt(paste(year, "01", "01", sep="-"), tz="GMT")
year.begin[1] <- begin
year.end <- as.POSIXlt(paste(year, "12", "31", sep="-"), tz="GMT")
year.end[length(year.end)] <- end
days <- as.numeric(year.end - year.begin) + 1
cbind(year, days)
+2
source

All Articles