Re: [R] expand.grid on contents of a list

2013-02-01 Thread arun
221 #5112 #6212 #122 #8222 A.K. - Original Message - From: Dimitri Liakhovitski To: r-help Cc: Sent: Friday, February 1, 2013 8:48 AM Subject: [R] expand.grid on contents of a list Hello! I have a list of variable length

Re: [R] expand.grid on contents of a list

2013-02-01 Thread Dimitri Liakhovitski
Oops, it was easier than I thought: expand.grid(X) Dimitri On Fri, Feb 1, 2013 at 8:48 AM, Dimitri Liakhovitski < dimitri.liakhovit...@gmail.com> wrote: > Hello! > I have a list of variable length. One example is: > X=vector("list",3) > X[[1]]=1:2 > X[[2]]=1:2 > X[[3]]=1:2 > How could I run expan

[R] expand.grid on contents of a list

2013-02-01 Thread Dimitri Liakhovitski
Hello! I have a list of variable length. One example is: X=vector("list",3) X[[1]]=1:2 X[[2]]=1:2 X[[3]]=1:2 How could I run expand.grid on the elements of X so that the results would be the same as expand.grid(1:2,1:2,1:2)? Thank you! Dimitri -- Dimitri Liakhovitski gfk.com

Re: [R] expand.grid (the half!)

2012-03-24 Thread Berend Hasselman
On 24-03-2012, at 16:08, Alaios wrote: > Dear all, > I am using expand.grid for calculating all the possible values between four > pairs. > > I would like to ask you if it is possible to filter the result out, so to > keep all unique pairs. In my algorithm the input c(1,2) produces the same >

Re: [R] expand.grid (the half!)

2012-03-24 Thread Søren Højsgaard
Alaios Sent: 24. marts 2012 16:09 To: R help Subject: [R] expand.grid (the half!) Dear all, I am using expand.grid for calculating all the possible values between four pairs. I would like to ask you if it is possible to filter the result out, so to keep all unique pairs. In my algorithm the input

[R] expand.grid (the half!)

2012-03-24 Thread Alaios
Dear all, I am using expand.grid for calculating all the possible values between four pairs. I would like to ask you if it is possible to filter the result out, so to keep all unique pairs. In my algorithm the input c(1,2) produces the same results as the c(2,1) so for example in the following

Re: [R] expand.grid using a matrix and a vector as input

2012-03-15 Thread Dimitris Rizopoulos
One possibility is to use something like the following: a1 <- matrix(1:4, 2, 2) a2 <- c(8, 9) cbind(a1[rep(1:nrow(a1), length(a2)), ], rep(a2, each = nrow(a1))) I hope it helps. Best, Dimitris On 3/15/2012 1:33 PM, eugen pircalabelu wrote: Hello R-users, I have the following question, fo

[R] expand.grid using a matrix and a vector as input

2012-03-15 Thread eugen pircalabelu
  Hello R-users,   I have the following question, for which my search did not really return any usable result. If I have a matrix a1, and a vector a2 like below   a1<-matrix(c(1:4),2,2) a2<-c(8,9)   is there any function like the expand.grid (or some clever calling of the function) such that it

Re: [R] expand.grid

2011-01-19 Thread Nick Sabbe
: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: Berwin A Turlach [mailto:ber...@maths.uwa.edu.au] Sent: woensdag 19 januari 2011 11:04 To: Nick Sabbe Cc: r-help@r-project.org Subject: Re: [R] expa

Re: [R] expand.grid

2011-01-19 Thread Berwin A Turlach
;g", "h", "i", "j", "k")) > > I would like to have a dataframe with all (unique) combinations of > all the factors present. Easy: R> expand.grid(lapply(dfr, levels)) c1 c2 c3 1 a d g 2 b d g 3 a e g 4 b e g 5 a d h 6 b

[R] expand.grid

2011-01-19 Thread Nick Sabbe
Hello list. I feel like an idiot. There exists a method called expand.grid which, from the documentation, appears to do just what I want, but then it doesn't, and I can't get it to behave. Given a dataframe dfr<-data.frame(c1=c("a", "b", NA, "a", "a"), c2=c("d", NA, "d", "e", "e"), c3

Re: [R] expand.grid game

2010-01-13 Thread baptiste auguie
It did take me a good night's sleep to understand it. I was stuck with the exact same question but I see now how the remaining balls are shared among all 8 urns (therefore cases with 11, 12, 13, ... 17 balls are also dealt with). Thanks again, baptiste 2010/1/12 Rolf Turner : > > On 13/01/2010,

Re: [R] expand.grid game --- never mind, I figured it out!

2010-01-12 Thread Rolf Turner
guie [mailto:baptiste.aug...@googlemail.com] Sent: Tuesday, January 12, 2010 12:20 PM To: Greg Snow Cc: r-help Subject: Re: [R] expand.grid game Nice --- am I missing something or was this closed form solution not entirely trivial to find? I ought to compile the various clever solutions given in

Re: [R] expand.grid game

2010-01-12 Thread Rolf Turner
On 13/01/2010, at 9:19 AM, Greg Snow wrote: How trivial is probably subjective, I don't think it is much above trivial. I would not have been surprised to see this question on an exam in my undergraduate (300 or junior level) probability course (the hard part was remembering the details f

Re: [R] expand.grid game

2010-01-12 Thread Greg Snow
08.8111 > -Original Message- > From: baptiste auguie [mailto:baptiste.aug...@googlemail.com] > Sent: Tuesday, January 12, 2010 12:20 PM > To: Greg Snow > Cc: r-help > Subject: Re: [R] expand.grid game > > Nice --- am I missing something or was this closed form solu

Re: [R] expand.grid game

2010-01-12 Thread baptiste auguie
...@r-project.org [mailto:r-help-boun...@r- >> project.org] On Behalf Of Brian Diggs >> Sent: Thursday, December 31, 2009 3:08 PM >> To: baptiste auguie; David Winsemius >> Cc: r-help >> Subject: Re: [R] expand.grid game >> >> baptiste auguie wrote: >> &

Re: [R] expand.grid game

2010-01-12 Thread Greg Snow
oject.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Brian Diggs > Sent: Thursday, December 31, 2009 3:08 PM > To: baptiste auguie; David Winsemius > Cc: r-help > Subject: Re: [R] expand.grid game > > baptiste auguie wrote: > > 2009/12/19 David Winsemius : > &

Re: [R] expand.grid game

2009-12-31 Thread Brian Diggs
baptiste auguie wrote: > 2009/12/19 David Winsemius : >> On Dec 19, 2009, at 9:06 AM, baptiste auguie wrote: >> >>> Dear list, >>> >>> In a little numbers game, I've hit a performance snag and I'm not sure >>> how to code this in C. >>> >>> The game is the following: how many 8-digit numbers have t

Re: [R] expand.grid game

2009-12-21 Thread Robin Hankin
Hi Ted. you've found a bug in the documentation for blockparts(). It should read "0 <= ai <= yi". I'll fix it before the next major release (which will include sampling without replacement from a multiset, Insha'Allah). Best wishes rksh (Ted Harding) wrote: I wonder whether this answers Bap

Re: [R] expand.grid game

2009-12-21 Thread Ted Harding
OOPS!! See correction below! On 21-Dec-09 08:45:13, Ted Harding wrote: > I wonder whether this answers Baptiste's question as asked. > > 1: An 8-digit number can have some digits equal to 0; >see Baptiste's comment "maxi <- 9 # digits from 0 to 9" > > 2: According to the man-page fror blockp

Re: [R] expand.grid game

2009-12-21 Thread Ted Harding
I wonder whether this answers Baptiste's question as asked. 1: An 8-digit number can have some digits equal to 0; see Baptiste's comment "maxi <- 9 # digits from 0 to 9" 2: According to the man-page fror blockparts in partitions, "all sets of a=(a1,...,an) satisfying Sum[ai] = n subject

Re: [R] expand.grid game

2009-12-21 Thread Robin Hankin
Hello again everybody. I fired off my reply before reading the correspondence about the leading zeros. You can also assume that there is at least one block at the leading position, [so that position can take 0,1,2,...,8 additional blocks] and distribute the remaining 16 blocks amongst all 8 pla

Re: [R] expand.grid game

2009-12-21 Thread baptiste auguie
Wow! system.time({ all = blockparts(rep(9,8),17) print( dim(all[,all[1,]!=0])[2] ) # remove leading 0s }) ## 229713 user system elapsed 0.160 0.068 0.228 In some ways I think this is close to Hadley's suggestion, though I didn't know how to implement it. Thanks a lot to everybody who

Re: [R] expand.grid game

2009-12-21 Thread Robin Hankin
Hi library(partitions) jj <- blockparts(rep(9,8),17) dim(jj) gives 318648 HTH rksh baptiste auguie wrote: Dear list, In a little numbers game, I've hit a performance snag and I'm not sure how to code this in C. The game is the following: how many 8-digit numbers have the sum of their di

Re: [R] expand.grid game

2009-12-19 Thread David Winsemius
On Dec 19, 2009, at 2:28 PM, baptiste auguie wrote: Hi, Thanks for the link, I guess it's some kind of a classic game. I'm a bit surprised by your timing, my ugly eval(parse()) "solution" definitely took less than one hour with a machine not so different from yours, system.time( for (i in 100

Re: [R] expand.grid game

2009-12-19 Thread baptiste auguie
This problem does yield some interesting and unexpected distributions. Here is another, the number of positive cases as a function of number of digits (8 in the original question) and of test value (17). maxi <- 9 N <- 5 test <- 17 foo <- function(N=2, test=1){ sum(rowSums(do.call(expand.grid, c(

Re: [R] expand.grid game

2009-12-19 Thread baptiste auguie
Hi, Thanks for the link, I guess it's some kind of a classic game. I'm a bit surprised by your timing, my ugly eval(parse()) "solution" definitely took less than one hour with a machine not so different from yours, system.time( for (i in 1079:1179) if (sumdigits(i)==17) {idx<-c(idx,i)})

Re: [R] expand.grid game

2009-12-19 Thread David Winsemius
On Dec 19, 2009, at 1:36 PM, baptiste auguie wrote: 2009/12/19 David Winsemius : On Dec 19, 2009, at 9:06 AM, baptiste auguie wrote: Dear list, In a little numbers game, I've hit a performance snag and I'm not sure how to code this in C. The game is the following: how many 8-digit numb

Re: [R] expand.grid game

2009-12-19 Thread hadley wickham
> I hope I have missed a better way to do this in R. Otherwise, I > believe what I'm after is some kind of C or C++ macro expansion, > because the number of loops should not be hard coded. Why not generate the list of integers that sum to 17, and then mix with 0s as appropriate? Hadley -- http:

Re: [R] expand.grid game

2009-12-19 Thread baptiste auguie
2009/12/19 David Winsemius : > > On Dec 19, 2009, at 9:06 AM, baptiste auguie wrote: > >> Dear list, >> >> In a little numbers game, I've hit a performance snag and I'm not sure >> how to code this in C. >> >> The game is the following: how many 8-digit numbers have the sum of >> their digits equal

Re: [R] expand.grid game

2009-12-19 Thread David Winsemius
On Dec 19, 2009, at 9:06 AM, baptiste auguie wrote: Dear list, In a little numbers game, I've hit a performance snag and I'm not sure how to code this in C. The game is the following: how many 8-digit numbers have the sum of their digits equal to 17? The brute-force answer could be: maxi <-

[R] expand.grid game

2009-12-19 Thread baptiste auguie
Dear list, In a little numbers game, I've hit a performance snag and I'm not sure how to code this in C. The game is the following: how many 8-digit numbers have the sum of their digits equal to 17? The brute-force answer could be: maxi <- 9 # digits from 0 to 9 N <- 5 # 8 is too large test <- 1

Re: [R] expand.grid applied to a matrix

2009-12-16 Thread Jean-Christophe Domenge
Many thanks for both replying and fixing the typo! jc On Tue, Dec 15, 2009 at 21:20, Charles C. Berry wrote: > On Tue, 15 Dec 2009, Jean-Christophe Domenge wrote: > > Dear R gurus, >> I'm looking for a way to expand a matrix to a data frame as detailed >> below: >> given a Matrix M with attribu

Re: [R] expand.grid applied to a matrix

2009-12-15 Thread Charles C. Berry
On Tue, 15 Dec 2009, Jean-Christophe Domenge wrote: Dear R gurus, I'm looking for a way to expand a matrix to a data frame as detailed below: given a Matrix M with attribute dimnames=list(c("a","b"),c("u","v")), return a data frame df.M with df.M$row df.M$col df.M$val "a""u"

[R] expand.grid applied to a matrix

2009-12-15 Thread Jean-Christophe Domenge
Dear R gurus, I'm looking for a way to expand a matrix to a data frame as detailed below: given a Matrix M with attribute dimnames=list(c("a","b"),c("u","v")), return a data frame df.M with df.M$row df.M$col df.M$val "a""u" M["a","u"] "b""v" M["b". "v

Re: [R] expand.grid() function

2008-06-23 Thread Wacek Kusnierczyk
Ken Knoblauch wrote: > > How about > > do.call("expand.grid", rep(list(c("u", "l")), 3)) > Var1 Var2 Var3 > 1uuu > 2luu > 3ulu > 4llu > 5uul > 6lul > 7ull > 8lll > > ... which can now be nicely gen

Re: [R] expand.grid() function

2008-06-23 Thread Gavin Simpson
desire for an answer does not > ensure that a reasonable answer can be extracted from a given body of > data. > ~ John Tukey > > -Oorspronkelijk bericht- > Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Namens Gavin Simpson > Verzonden: maandag 23 juni 2008 15:51

Re: [R] expand.grid() function

2008-06-23 Thread ONKELINX, Thierry
D] Namens Gavin Simpson Verzonden: maandag 23 juni 2008 15:51 Aan: Megh Dal CC: [EMAIL PROTECTED] Onderwerp: Re: [R] expand.grid() function On Mon, 2008-06-23 at 06:16 -0700, Megh Dal wrote: > Hi, > > I have one question on expand.grid() function. > > When I write following

Re: [R] expand.grid() function

2008-06-23 Thread Ken Knoblauch
Megh Dal yahoo.com> writes: > I have one question on expand.grid() function. > When I write following syntax :expand.grid(c("u", "l"), >c("u", "l"), c("u", "l")) I get following as > desired : > Var1 Var2 Var3 > 1uuu > 2luu > 3ulu > 4llu > 5

Re: [R] expand.grid() function

2008-06-23 Thread Gavin Simpson
On Mon, 2008-06-23 at 06:16 -0700, Megh Dal wrote: > Hi, > > I have one question on expand.grid() function. > > When I write following syntax :expand.grid(c("u", "l"), c("u", "l"), > c("u", "l")) I get following as desired : > Var1 Var2 Var3 > 1uuu > 2luu > 3

[R] expand.grid() function

2008-06-23 Thread Megh Dal
Hi, I have one question on expand.grid() function. When I write following syntax :expand.grid(c("u", "l"), c("u", "l"), c("u", "l")) I get following as desired : Var1 Var2 Var3 1uuu 2luu 3ulu 4llu 5uul 6lul 7

Re: [R] expand.grid using a repeated vector as a parameter

2008-05-02 Thread Greg Snow
> From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Simon Parker > Sent: Friday, May 02, 2008 11:50 AM > To: r-help@r-project.org > Subject: [R] expand.grid using a repeated vector as a parameter > > Hello. > > > I'm trying to do this (not necessar

Re: [R] expand.grid using a repeated vector as a parameter

2008-05-02 Thread Prof Brian Ripley
?do.call On Fri, 2 May 2008, Simon Parker wrote: Hello. I'm trying to do this (not necessarily 0:1) : expand.grid ( 0:1, 0:1, 0:1, 0:1, 0:1) etc..etc. but I want to have control over how many 0:1 are included. Any ideas please ? Thankyou. Simon Parker Imperial College -

[R] expand.grid using a repeated vector as a parameter

2008-05-02 Thread Simon Parker
Hello. I'm trying to do this (not necessarily 0:1) : expand.grid ( 0:1, 0:1, 0:1, 0:1, 0:1) etc..etc. but I want to have control over how many 0:1 are included. Any ideas please ? Thankyou. Simon Parker Imperial College - A Smarter Email.

Re: [R] expand.grid function

2007-12-25 Thread Satoshi Takahama
; To: r-help@r-project.org Sent: Sunday, December 23, 2007 7:59:49 PM Subject: [R] expand.grid function useR's, I have used expand.grid() several times and like the results it gives me. I am now trying something with it that I have not been able to get to work. For any n column matrix

Re: [R] expand.grid function

2007-12-23 Thread dxc13
Yes, that works perfectly. Thank you for your help! Derek Charilaos Skiadas-3 wrote: > > Hi Derek, > On Dec 23, 2007, at 10:59 PM, dxc13 wrote: > >> >> useR's, >> >> I have used expand.grid() several times and like the results it >> gives me. I >> am now trying something with it that I h

Re: [R] expand.grid function

2007-12-23 Thread Charilaos Skiadas
Hi Derek, On Dec 23, 2007, at 10:59 PM, dxc13 wrote: > > useR's, > > I have used expand.grid() several times and like the results it > gives me. I > am now trying something with it that I have not been able to get to > work. > For any n column matrix I would like to run this function on those

[R] expand.grid function

2007-12-23 Thread dxc13
useR's, I have used expand.grid() several times and like the results it gives me. I am now trying something with it that I have not been able to get to work. For any n column matrix I would like to run this function on those n columns and store the results. For example, if my matrix has 1 colum

Re: [R] expand.grid overflows?

2007-11-18 Thread Adrian Dusa
On Friday 16 November 2007, francogrex wrote: > >cbn<-as.matrix(expand.grid( rep( list(0:1), 50))) > > Error in rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) : > invalid 'times' value > In addition: Warning message: > In rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) : >

Re: [R] expand.grid overflows?

2007-11-16 Thread Dimitris Rizopoulos
age - From: "francogrex" <[EMAIL PROTECTED]> To: Sent: Friday, November 16, 2007 12:35 PM Subject: [R] expand.grid overflows? > >>cbn<-as.matrix(expand.grid( rep( list(0:1), 50))) > > Error in rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) : >

[R] expand.grid overflows?

2007-11-16 Thread francogrex
>cbn<-as.matrix(expand.grid( rep( list(0:1), 50))) Error in rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) : invalid 'times' value In addition: Warning message: In rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) : NAs introduced by coercion But I'm only interested in c