[R] Problem with expand.grid

David Winsemius dwinsemius at comcast.net
Tue Dec 22 17:30:42 CET 2009


On Dec 22, 2009, at 11:19 AM, Keith Jewell wrote:

> Just confirming it isn't the bug fixed in 2.11.0dev, and giving an  
> even
> simpler example:
>
> R version 2.11.0 Under development (unstable) (2009-12-20 r50794)
>
>> expand.grid(data.frame(y=1:10, t=1:10))
> Error in `[[<-.data.frame`(`*tmp*`, i, value = c(1L, 2L, 3L, 4L, 5L,  
> 6L,  :
>  replacement has 100 rows, data has 10

Did you mean to type:

expand.grid( lapply(data.frame(y=1:10, t=1:10), "["))
# no error
# ???
-- 
David

>
> "Keith Jewell" <k.jewell at campden.co.uk> wrote in message
> news:hgqqja$rku$1 at ger.gmane.org...
>> 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list