[R] Problem with expand.grid

Keith Jewell k.jewell at campden.co.uk
Tue Dec 22 17:33:54 CET 2009


<bangs head on desk>

Thanks, Prof Ripley (and everyone else who's responding while I type this!).

I thought I was being stupid. What I wanted was:
          expand.grid(lapply(dDF, unique))
which works fine!

<hangs head in shame>

Seasonal greetings to all,

Keith Jewell

"Prof Brian Ripley" <ripley at stats.ox.ac.uk> wrote in message 
news:alpine.LFD.2.00.0912221619440.20175 at gannet.stats.ox.ac.uk...
> 1) Look at the help: a data frame may be a list, but do pass a list such 
> as unclass(dDF) when it says 'list'.
>
> 2) You have 7 columns of 10 items, which gives 10 million rows.  Is that 
> really what you want (especially as some of the columns are constant)? 
> It's an object of ca 500MB.
>
> On Tue, 22 Dec 2009, Keith Jewell wrote:
>
>> Hi All,
>>
>> This example code
>> ----------------
>> dDF <- structure(list(y = c(4.75587, 4.8451, 5.04139, 4.85733, 5.20412,
>> 5.92428, 5.69897, 4.78958, 4, 4), t = c(0, 48, 144, 192, 240,
>> 312, 360, 0, 48, 144), Batch = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1
>> ), T = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2), pH = c(4.6, 4.6, 4.6,
>> 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6), S = c(0, 0, 0, 0, 0, 0, 0,
>> 0, 0, 0), N = c(0, 0, 0, 0, 0, 0, 0, 80, 80, 80)), .Names = c("y",
>> "t", "Batch", "T", "pH", "S", "N"), row.names = c(NA, 10L), class =
>> "data.frame")
>> str(dDF)
>> expand.grid(dDF)
>> ------------------------------------
>> 'hangs' for a while and then gives an error
>>
>> Error in `[[<-.data.frame`(`*tmp*`, i, value = c(4.75587, 4.8451, 
>> 5.04139,
>> :
>>  replacement has 10000000 rows, data has 10
>>
>> In NEWS.R-2.11.0dev I read:
>>    o The new (in 2.9.0) 'stringsAsFactors' argument to expand.grid()
>> was not working: it now does work but has default TRUE for
>> backwards compatibility.
>>
>> but I don't think that's relevant, I have no factors.
>>
>> I'm probably being silly. Can anyone point out where?
>>
>> Best...
>>
>> Keith Jewell
>>
>> --please do not edit the information below--
>>
>> Version:
>> platform = i386-pc-mingw32
>> arch = i386
>> os = mingw32
>> system = i386, mingw32
>> status = Patched
>> major = 2
>> minor = 10.1
>> year = 2009
>> month = 12
>> day = 21
>> svn rev = 50796
>> language = R
>> version.string = R version 2.10.1 Patched (2009-12-21 r50796)
>>
>> Windows Server 2003 x64 (build 3790) Service Pack 2
>>
>> Locale:
>> LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United
>> Kingdom.1252;LC_MONETARY=English_United
>> Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252
>>
>> Search Path:
>> .GlobalEnv, package:stats, package:graphics, package:grDevices,
>> package:utils, package:datasets, package:methods, Autoloads, package:base
>>
>> ______________________________________________
>> 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.
>>
>
> -- 
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>




More information about the R-help mailing list