It worked fine for me without using much memory.  Take a look at you
statements and you will see that you are missing a comma on the dimensions:

> n <- 58000
> max_out <- data.frame(Lat=runif(n), Long=runif(n), Model=sample(1:12, n
,TRUE),
+     Obs=sample(1:12, n, TRUE))
> str(max_out)
'data.frame':   58000 obs. of  4 variables:
 $ Lat  : num  0.266 0.372 0.573 0.908 0.202 ...
 $ Long : num  0.295 0.286 0.989 0.413 0.924 ...
 $ Model: int  2 6 5 3 1 3 2 12 6 3 ...
 $ Obs  : int  11 10 4 9 8 4 1 8 4 8 ...
> object.size(max_out)
1392576 bytes
> gc()
         used (Mb) gc trigger (Mb) max used (Mb)
Ncells 126997  3.4     350000  9.4   350000  9.4
Vcells 256113  2.0    1091825  8.4  1028962  7.9
> # notice additional commas
> value <- cbind(max_out,
+     dif=ifelse(max_out[,3] - max_out[,4]> 6, max_out[,3] -
(max_out[,4]+12), max_out[,3] - max_out[,4]))
> str(value)
'data.frame':   58000 obs. of  5 variables:
 $ Lat  : num  0.266 0.372 0.573 0.908 0.202 ...
 $ Long : num  0.295 0.286 0.989 0.413 0.924 ...
 $ Model: int  2 6 5 3 1 3 2 12 6 3 ...
 $ Obs  : int  11 10 4 9 8 4 1 8 4 8 ...
 $ dif  : num  -9 -4 1 -6 -7 -1 1 4 2 -5 ...
> head(value,20)
          Lat       Long Model Obs dif
1  0.26550866 0.29545897     2  11  -9
2  0.37212390 0.28644093     6  10  -4
3  0.57285336 0.98867753     5   4   1
4  0.90820779 0.41280923     3   9  -6
5  0.20168193 0.92394115     1   8  -7
6  0.89838968 0.51848851     3   4  -1
7  0.94467527 0.71813809     2   1   1
8  0.66079779 0.78323081    12   8   4
9  0.62911404 0.84581027     6   4   2
10 0.06178627 0.01757108     3   8  -5
11 0.20597457 0.39770773    11   6   5
12 0.17655675 0.62580029     7   4   3
13 0.68702285 0.44794291     2   8  -6
14 0.38410372 0.08462264     7   8  -1
15 0.76984142 0.98978339     6   7  -1
16 0.49769924 0.42655140    12   2  -2
17 0.71761851 0.03631297    11   6   5
18 0.99190609 0.04994102     7   5   2
19 0.38003518 0.79581617     1   2  -1
20 0.77744522 0.40658383     9   6   3
> gc()
         used (Mb) gc trigger (Mb) max used (Mb)
Ncells 129604  3.5     350000  9.4   350000  9.4
Vcells 488484  3.8    1610438 12.3  1605598 12.3
>
> # error -- not run--   Incorrect indexing
> #--value_err <- cbind(max_out,
> #--    dif=ifelse(max_out[3] - max_out[4]> 6, max_out[3] -
(max_out[4]+12), max_out[3] - max_out[4]))
>
>



On Mon, May 25, 2009 at 11:00 AM, Steve Murray <smurray...@hotmail.com>wrote:

>
> 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]]
>
> ______________________________________________
> R-help@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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to