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
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 "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 >
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
Keith Jewell <k.jewell <at> campden.co.uk> writes:> > 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 erroror even simpler expand.grid(data.frame(1:3, 1:3)) Error in `[[<-.data.frame`(`*tmp*`, i, value = c(1L, 2L, 3L, 1L, 2L, 3L, : replacement has 9 rows, data has 3 but why do this on a data frame as it works fine on a list expand.grid(list(1:3, 1:3)) Var1 Var2 1 1 1 2 2 1 3 3 1 4 1 2 5 2 2 6 3 2 7 1 3 8 2 3 9 3 3 or just vectors expand.grid(1:3, 1:3) Var1 Var2 1 1 1 2 2 1 3 3 1 4 1 2 5 2 2 6 3 2 7 1 3 8 2 3 9 3 3 -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen L?pine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html
>>>>> "KJ" == Keith Jewell <k.jewell at campden.co.uk> >>>>> on Tue, 22 Dec 2009 16:02:49 -0000 writes:KJ> Hi All, KJ> This example code KJ> ---------------- KJ> dDF <- structure(list(y = c(4.75587, 4.8451, 5.04139, 4.85733, 5.20412, KJ> 5.92428, 5.69897, 4.78958, 4, 4), t = c(0, 48, 144, 192, 240, KJ> 312, 360, 0, 48, 144), Batch = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1 KJ> ), T = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2), pH = c(4.6, 4.6, 4.6, KJ> 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6), S = c(0, 0, 0, 0, 0, 0, 0, KJ> 0, 0, 0), N = c(0, 0, 0, 0, 0, 0, 0, 80, 80, 80)), .Names = c("y", KJ> "t", "Batch", "T", "pH", "S", "N"), row.names = c(NA, 10L), class = KJ> "data.frame") KJ> str(dDF) KJ> expand.grid(dDF) KJ> ------------------------------------ KJ> 'hangs' for a while and then gives an error KJ> Error in `[[<-.data.frame`(`*tmp*`, i, value = c(4.75587, 4.8451, 5.04139, KJ> : KJ> replacement has 10000000 rows, data has 10 KJ> In NEWS.R-2.11.0dev I read: KJ> o The new (in 2.9.0) 'stringsAsFactors' argument to expand.grid() KJ> was not working: it now does work but has default TRUE for KJ> backwards compatibility. KJ> but I don't think that's relevant, I have no factors. KJ> I'm probably being silly. yes, probably ;-) At least you are using expand.grid() in an unusual way. [What are you trying to use expand.grid() for ?] E.g., (dataframe) variable 'S' has only values '0'. One thing which works and may be close to what you want is the following: dU <- lapply(dDF, unique) r <- expand.grid(dU) Here's the illustration about it :> str(dDF)'data.frame': 10 obs. of 7 variables: $ y : num 4.76 4.85 5.04 4.86 5.2 ... $ t : num 0 48 144 192 240 312 360 0 48 144 $ Batch: num 1 1 1 1 1 1 1 1 1 1 $ T : num 2 2 2 2 2 2 2 2 2 2 $ pH : num 4.6 4.6 4.6 4.6 4.6 4.6 4.6 4.6 4.6 4.6 $ S : num 0 0 0 0 0 0 0 0 0 0 $ N : num 0 0 0 0 0 0 0 80 80 80> > str(dU <- lapply(dDF, unique))List of 7 $ y : num [1:9] 4.76 4.85 5.04 4.86 5.2 ... $ t : num [1:7] 0 48 144 192 240 312 360 $ Batch: num 1 $ T : num 2 $ pH : num 4.6 $ S : num 0 $ N : num [1:2] 0 80> r <- expand.grid(dU) > str(r)'data.frame': 126 obs. of 7 variables: $ y : num 4.76 4.85 5.04 4.86 5.2 ... $ t : num 0 0 0 0 0 0 0 0 0 48 ... $ Batch: num 1 1 1 1 1 1 1 1 1 1 ... $ T : num 2 2 2 2 2 2 2 2 2 2 ... $ pH : num 4.6 4.6 4.6 4.6 4.6 4.6 4.6 4.6 4.6 4.6 ... $ S : num 0 0 0 0 0 0 0 0 0 0 ... $ N : num 0 0 0 0 0 0 0 0 0 0 ... - attr(*, "out.attrs")=List of 2 ..$ dim : Named int 9 7 1 1 1 1 2 .. ..- attr(*, "names")= chr "y" "t" "Batch" "T" ... ..$ dimnames:List of 7 .. ..$ y : chr "y=4.75587" "y=4.84510" "y=5.04139" "y=4.85733" ... .. ..$ t : chr "t= 0" "t= 48" "t=144" "t=192" ... .. ..$ Batch: chr "Batch=1" .. ..$ T : chr "T=2" .. ..$ pH : chr "pH=4.6" .. ..$ S : chr "S=0" .. ..$ N : chr "N= 0" "N=80">--- may be that helps? Regards, Martin Maechler, ETH Zurich