aggregate combination data
Hello, I'm cc'ing R-Help. Sorry but your question was asked 3.5 years ago, I really don't remember it. Can you please post a question to R-Help, with a reproducible example that describes your problem? Rui Barradas ? Citando catalin roibu <catalinroibu at gmail.com>:
Dear Rui, ? I helped me some time ago with a code..... regarding aggregated data from combination values. I solved partial the problem...I have one single question. From combination I have a number of data frames. I want for each combination to insert a column with combination ID (C1 for first iteration to Cn for last one)? Is there a possibility to do that? ? Thank you very much! ? best regards! ? Catalin ? On 15 November 2012 at 13:29, Rui Barradas <ruipbarradas at sapo.pt> wrote:
Hello, Sorry but now I don't understand, what you are saying is that you want all the results in just one df? all <- do.call(rbind, result) But this creates just one very large df. Hope this helps, Rui Barradas Em 15-11-2012 10:42, catalin roibu escreveu:
Hello again, I solve that problem. But I have another one. I want my result is this form: plot d 1 15.00 1 27.50 1 10.50 1 12.25 2 14.00 2 32.50 ? 99 32.00 99 42.00 100 57.00 100 16.00 100 8.00 100 56.00 in final values of d for all combination possible. Thank you very much! On 15 November 2012 12:10, catalin roibu <catalinroibu at gmail.com> wrote: ?
Hello again,
Wen I want to show all combination 100C3, I have this problem:
? [ reached getOption("max.print") -- omitted 2498631 rows ]
How can you do?
On 14 November 2012 19:28, Rui Barradas <ruipbarradas at sapo.pt> wrote:
?
Simple Just use unlist(result). Hope this helps, Rui Barradas Em 14-11-2012 17:13, catalin roibu escreveu: ?
hello again, It's ok now, but I have a little problem. I want to remove the combination number (1 to 4950). In this mode the all data are continuous. Thank you! *[[4271]]* ? ? ? plot? ? ?d 218? ?74 11.50 219? ?74 12.00 220? ?74 10.50 221? ?74 80.75 251? ?87 15.25 252? ?87 93.50 253? ?87 14.50 254? ?87 83.75 255? ?87? 9.75 256? ?87 95.00 *[[4272]]* ? ? ? plot? ? ?d 218? ?74 11.50 219? ?74 12.00 220? ?74 10.50 221? ?74 80.75 257? ?88 13.50 258? ?88 16.25 259? ?88? 8.50 260? ?88? 8.50 On 14 November 2012 18:56, catalin roibu <catalinroibu at gmail.com> wrote: ? thank you very much!
On 14 November 2012 18:47, Rui Barradas <ruipbarradas at sapo.pt> wrote: ? Hello,
Ok, I think this is it.
fun <- function(x, k){
? ? ? n <- length(x)
? ? ? cmb <- combn(n, k)
? ? ? apply(cmb, 2, function(j) x[j])
}
fun2 <- function(x, p){
? ? ? idx <- x[["plot"]] %in% p
? ? ? x[idx, ]
}
uplot <- unique(dat$plot)
plots <- fun(uplot, 2)
apply(plots, 2, function(p) fun2(dat, p))
There's a total of 4560 df's returned.
Rui Barradas
Em 14-11-2012 14:22, catalin roibu escreveu:
? ?Hello again,
?
I want all d values for all posible combination, 100C2 (all d values
for
plot 1 with all d values in the plot 2.......all d values from plot 1
with
all d values from plot 100, ......all d values from plot 99
with all d
values from plot 100). Total 4950 values
structure(list(plot = c(1L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 3L,
4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 7L, 7L, 7L, 7L, 8L, 9L, 9L,
10L, 10L, 10L, 11L, 11L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L,
13L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L,
16L, 16L, 16L, 17L, 17L, 17L, 18L, 18L, 18L, 19L, 19L, 19L, 19L,
20L, 20L, 20L, 21L, 22L, 22L, 22L, 23L, 23L, 23L, 23L, 23L, 24L,
24L, 25L, 25L, 25L, 25L, 26L, 26L, 26L, 26L, 26L, 27L, 27L, 27L,
27L, 27L, 28L, 28L, 28L, 28L, 29L, 29L, 29L, 30L, 30L, 30L, 30L,
32L, 32L, 32L, 32L, 33L, 34L, 34L, 34L, 35L, 36L, 36L, 36L, 36L,
37L, 37L, 37L, 38L, 38L, 38L, 38L, 38L, 38L, 39L, 39L, 39L, 39L,
39L, 39L, 40L, 40L, 40L, 41L, 41L, 42L, 42L, 42L, 42L, 42L, 42L,
42L, 43L, 44L, 44L, 44L, 45L, 45L, 46L, 46L, 47L, 48L, 48L, 48L,
49L, 50L, 50L, 50L, 50L, 50L, 50L, 51L, 51L, 52L, 52L, 53L, 53L,
53L, 54L, 54L, 54L, 54L, 55L, 56L, 56L, 57L, 57L, 57L, 58L, 58L,
58L, 59L, 60L, 60L, 60L, 61L, 61L, 62L, 62L, 63L, 63L, 64L, 64L,
64L, 65L, 65L, 66L, 66L, 66L, 67L, 67L, 67L, 68L, 68L, 68L, 69L,
69L, 70L, 70L, 71L, 71L, 73L, 73L, 73L, 73L, 74L, 74L, 74L, 74L,
75L, 75L, 75L, 75L, 76L, 76L, 76L, 76L, 78L, 78L, 78L, 79L, 79L,
80L, 80L, 81L, 81L, 81L, 81L, 82L, 82L, 82L, 83L, 83L, 83L, 84L,
85L, 85L, 85L, 87L, 87L, 87L, 87L, 87L, 87L, 88L, 88L, 88L, 88L,
89L, 89L, 90L, 91L, 91L, 91L, 91L, 91L, 92L, 93L, 93L, 94L, 95L,
95L, 95L, 95L, 96L, 96L, 96L, 97L, 97L, 98L, 98L, 98L, 98L, 99L,
100L, 100L, 100L, 100L, 100L), d = c(15, 27.5, 10.5, 12.25, 14,
32.5, 80, 49.5, 15.25, 13.5, 12.25, 12, 72.5, 68.5, 12, 9.25,
12.75, 13.5, 28, 38, 10.25, 62.5, 73.5, 61.5, 54.5, 40, 24.25,
43, 13, 20.75, 23.25, 25.5, 7.25, 11.25, 60.5, 11.25, 8, 11,
93.25, 8.75, 10.5, 35, 19, 79, 60.5, 64.5, 53.75, 8.75, 9.75,
9.5, 12.5, 21, 10, 46.75, 48.5, 77.5, 23.75, 60, 11.5, 13.25,
13.75, 76.25, 12.5, 8, 70, 47.75, 52.25, 49.25, 11.25, 12.5,
15.25, 20.25, 19.25, 20.5, 13.5, 86, 23, 10.5, 20.25, 27.75,
11.25, 32.5, 28.25, 12.5, 14.75, 83, 19.25, 14.25, 21.5, 26.75,
11.25, 56, 19.75, 55.25, 10, 16.75, 12.5, 19.75, 13, 19.25, 9.75,
75, 12.5, 11.25, 14.5, 69.5, 13.75, 15.75, 63.75, 18.75, 9.25,
68, 29, 17.75, 15, 27.25, 10.25, 13.5, 68.25, 9.25, 13, 16.75,
36.5, 11.25, 87.25, 69.75, 66.25, 15.25, 14.75, 9, 15.75, 17.75,
82, 13.25, 20, 82.5, 86.5, 7.75, 14.5, 9.25, 95.5, 8.25, 12,
13.5, 16.5, 69, 15.5, 12, 42, 79.5, 40.75, 13.25, 10, 76.5, 10.75,
16.5, 12.5, 60.25, 11.25, 17, 63.25, 96, 14.25, 49.5, 56.5, 18,
84.25, 69.5, 12, 64.75, 48.5, 8.25, 29, 68, 7.25, 79.75, 55,
75.5, 60.75, 57.5, 61, 15.25, 69, 52.25, 98, 13.25, 14.25, 60.75,
14.25, 12.25, 56.5, 18, 76.25, 20.75, 10.5, 63.25, 12.5, 11.75,
84.5, 33.25, 77.75, 71.5, 11.5, 13.5, 19, 31.5, 27.25, 21, 13.25,
12.5, 31.75, 22, 20, 58.5, 40.5, 62, 85.5, 11.5, 12, 10.5, 80.75,
55.5, 87, 42.5, 70.5, 9.25, 56, 73.75, 12.75, 11, 59, 18.75,
10.75, 81, 14, 33.5, 13.25, 69.25, 8.75, 14.5, 63, 89.25, 73.75,
48.25, 58, 11.5, 17.25, 12.75, 10, 11.5, 15.25, 93.5, 14.5, 83.75,
9.75, 95, 13.5, 16.25, 8.5, 8.5, 70, 9.75, 72.5, 71.5, 9.5, 83,
43.75, 51, 55.25, 75.5, 61, 53.75, 60, 12.25, 47, 13.75, 86.5,
14.5, 10, 9.75, 12, 13.75, 31.75, 64.75, 13.75, 83.5, 45.5, 67,
84.5, 57.5, 46)), .Names = c("plot", "d"), class = "data.frame",
row.names
= c(NA,
-291L))
On 14 November 2012 16:04, Rui Barradas <ruipbarradas at sapo.pt> wrote:
? ?Hello,
?
Try the following.
fun <- function(x, k){
? ? ? ?n <- length(x)
? ? ? ?cmb <- combn(n, k)
? ? ? ?apply(cmb, 2, function(j) x[j])
}
uplot <- unique(dat$plot)
fun(uplot, 2)
Hope this helps,
Rui Barradas
Em 14-11-2012 13:42, catalin roibu escreveu:
? ? Hello again,
? I want the individual plots aggregated by k-combination.
I have 100
plots. ? ? ?For example I want all values of diameter (d) for combination of two plots (plot 1 and 2, plot 1 and 3 etc) taken by 100. On 14 November 2012 15:38, Rui Barradas <ruipbarradas at sapo.pt> wrote: ? ? Hello, ? This will give you a list of 19 elements, each element k is a
matrix of all combinations of 19 taken k at a time. cmb <- lapply(seq_len(nrow(dat)), function(k) combn(nrow(dat), k)) d <- dat[["d"]] lapply(cmb, function(cc) apply(cc, 2, function(j) d[j])) Hope this helps, Rui Barradas Em 14-11-2012 13:32, catalin roibu escreveu: ? ? ?I want to aggregate all values of diameter after the combination between ? ?plots. For example all diameter (d) values for combination of n plots ?
taken by k. On 14 November 2012 15:28, Rui Barradas <ruipbarradas at sapo.pt> wrote: ? ? ?Hello, ? ?You forgot to Cc the list. ?
As for your question, you want all possible combinations of rows? For all possible values of k in 1:19? ? ? ?sum(sapply(1:19, function(k) choose(19, k))) [1] 524287 Or you want to split the data.frame by plot and the have all possible combinations? ? ? ?sum(sapply(1:10, function(k) choose(10, k))) [1] 1023 ? ? sum(sapply(1:9, function(k) choose(9, k))) ? ? ?[1] 511
? Rui Barradas
Em 14-11-2012 11:31, catalin roibu escreveu: ? ? ? I don't want to sum the data from all combination. I want to group ? ? (aggregate) the all values resulted from all combination possible. ? plot d
1 14 1 13 1 12 1 14 1 18 1 20 1 21 1 43 1 108 1 43 2 41 2 61 2 83 2 61 2 84 2 45 2 21 2 12 2 11 On 14 November 2012 13:25, Rui Barradas <ruipbarradas at sapo.pt> wrote: ? ? ? Hello, ? ? Please use ?dput to post your data. ? dput(MyData)? # paste the output of this in a post.
And you must be more clear, what does "aggregate" mean? To sum? In the mean time see ?combn Hope this helps, Rui Barradas Em 14-11-2012 11:11, catalin roibu escreveu: ? ? ? Dear R users, ? ? I want to aggregate all *d *data from? all combination of n *plots* ? taken
by k. Thank very much! My data is like that: ? ? ? ? ? ? ? ? ? plot? ? ? ? ? ? ? d? 1 14? 1 13? 1 12? 1 14 ? 1 18? 1 20 ? ? ?1 21 ? ? ? ?1 43? 1 108? 1 43? 2 41? 2 61? 2 83? 2 61? 2 84? 2 45? 2 21? 2 12 ? ?2 11 ? ? ? ?...? 100 ? ? ? ? ? ? ?10 100? ? ? ?12 ?
-- --- Catalin-Constantin ROIBU Forestry engineer, PhD Forestry Faculty of Suceava Str. Universitatii no. 13, Suceava, 720229, Romania office phone? ? ?+4 0230 52 29 78, ext. 531[1] mobile phone? ?+4 0745 53 18 01[2] ? ? ? ? ? ? ? ? ? ? ? ? ?+4 0766 71 76 58[3] FAX:? ? ? ? ? ? ? ? +4 0230 52 16 64[4] silvic.usv.ro[5] ?
-- --- Catalin-Constantin ROIBU Forestry engineer, PhD Forestry Faculty of Suceava Str. Universitatii no. 13, Suceava, 720229, Romania office phone? ? ?+4 0230 52 29 78, ext. 531[1] mobile phone? ?+4 0745 53 18 01[2] ? ? ? ? ? ? ? ? ? ? ? ? +4 0766 71 76 58[3] FAX:? ? ? ? ? ? ? ? +4 0230 52 16 64[4] silvic.usv.ro[5] ?
?
? ? -- ? - - Catalin-Constantin ROIBU? ? Lecturer PhD,?Forestry engineer Forestry Faculty of Suceava Str. Universitatii no. 13, Suceava, 720229, Romania office phone ? ? ?+4 0230 52 29 78, ext. 531 mobile phone ? ?+4 0745 53 18 01 FAX: ??? ??? ?????? +4 0230 52 16 64 silvic.usv.ro[6] ?
? Liga??es: --------- [1] tel:%2B4%200230%2052%2029%2078%2C%20ext.%20531 [2] tel:%2B4%200745%2053%2018%2001 [3] tel:%2B4%200766%2071%2076%2058 [4] tel:%2B4%200230%2052%2016%2064 [5] http://silvic.usv.ro [6] http://www.usv.ro/