[R] Memory problems when using ifelse
Steve Murray
smurray444 at hotmail.com
Mon May 25 17:00:59 CEST 2009
Dear R Users,
I have a data frame of 4 columns and ~58000 rows, the top of which looks like this:
> head(max_out)
Latitude Longitude Model Obs
1 -0.25 -49.25 4 4
2 -0.25 -50.25 4 5
3 -0.25 -50.75 4 4
4 -0.25 -51.25 3 11
5 -0.25 -51.75 6 4
6 -0.25 -52.25 12 5
The above shows, for each coordinate point, the month (1 = January, 12 = December) in which the maximum value occurs for the variable I'm testing.
I'm hoping to add an extra column onto this data frame to show the difference between the model and the observations, in the form of: max_out[3] - max_out[4].
This is fine for the simple cases, but row 6 is an example where this approach fails. I know from the data that model is predicting the maximum value too early (i.e. -5 months) rather than 7 months too late (as implied by the simple max_out[3] - max_out[4] calculation).
In order to get round such cases, if the result of the simple calculation is>6, then I want to add 12 to the offending value (!) in the 'Obs' column in order to get the 'correct' value. For example, in row 6, as the current calculation results in a difference of 7, I instead want to do 12-(5+12) (corresponding to Obs+12 - Model) = -5.
Similarly, in row 4, I'd like to do the reverse (i.e. -12 for where the calculation results in a value <- cbind(max_out[1:2], ifelse(max_out[3] - max_out[4]> 6, max_out[3] - (max_out[4]+12), max_out[3] - max_out[4])) # If diff is not>6, then output original difference value
Error: cannot allocate vector of size 221 Kb
In addition: Warning messages:
1: In data.frame(..., check.names = FALSE) :
Reached total allocation of 999Mb: see help(memory.size)
2: In data.frame(..., check.names = FALSE) :
Reached total allocation of 999Mb: see help(memory.size)
I suspect I'm doing something wrong, as the calculation shouldn't be that computationally intense!
Any help or advice to help get me on the right tracks would be much appreciated.
Many thanks,
Steve
_________________________________________________________________
[[elided Hotmail spam]]
More information about the R-help
mailing list