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
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 expand.grid on
221
#5112
#6212
#122
#8222
A.K.
- Original Message -
From: Dimitri Liakhovitski dimitri.liakhovit...@gmail.com
To: r-help r-help@r-project.org
Cc:
Sent: Friday, February 1, 2013 8:48 AM
Subject: [R] expand.grid on contents
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
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 c(1,2
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
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
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, for
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=c(g, h, i, j,
with c3=k).
R dfrpart - lapply(dfr[1:4,], factor)
R expand.grid(lapply(dfrpart, 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 d h
7 a e h
8 b e h
9 a d i
10 b d i
11 a e i
12 b e i
13 a d j
14 b d j
15 a e j
16 b e j
, 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] expand.grid
G'day Nick,
On Wed, 19 Jan 2011 09:43:56 +0100
Nick
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
[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 dwinsem...@comcast.net:
On Dec 19, 2009, at 9:06 AM
] 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 dwinsem...@comcast.net:
On Dec 19, 2009, at 9:06 AM, baptiste auguie wrote:
Dear list
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 solution not
entirely trivial to find?
I ought to compile
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
...@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 this thread
someday, it's
baptiste auguie wrote:
2009/12/19 David Winsemius dwinsem...@comcast.net:
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
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
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
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
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
to
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 blockparts in
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
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 - 17
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 -
2009/12/19 David Winsemius dwinsem...@comcast.net:
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
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
--
On Dec 19, 2009, at 1:36 PM, baptiste auguie wrote:
2009/12/19 David Winsemius dwinsem...@comcast.net:
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
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)})
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,
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
Many thanks for both replying and fixing the typo!
jc
On Tue, Dec 15, 2009 at 21:20, Charles C. Berry cbe...@tajo.ucsd.eduwrote:
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
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
au M[a,u]
bv M[b. v]
au
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
au
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
7ul
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
3ulu
4
Megh Dal megh74 at 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
5u
: 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 syntax :expand.grid(c(u, l), c(u, l),
c(u, l)) I
PROTECTED]
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
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 generalized and
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.
?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
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 necessarily 0:1) :
expand.grid ( 0:1, 0:1, 0:1, 0:1, 0:1)
etc
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
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
n
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 have not been
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
: francogrex [EMAIL PROTECTED]
To: r-help@r-project.org
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) :
invalid 'times' value
In addition: Warning message
49 matches
Mail list logo