[R] exporting a split list

jim holtman jholtman at gmail.com
Tue Nov 27 14:46:14 CET 2007


Here is a start.  You can add code to limit the length of 'examples'
and add the header line:

> x <- list('1'=c('a','b','c'), '10'=letters[1:20])
> output <- lapply(names(x), function(values){
+     paste(values, length(values), paste(x[[values]], collapse=' '),
"\n", sep='\t')
+ })
> cat(do.call('rbind', output), sep='')
1       1       a b c
10      1       a b c d e f g h i j k l m n o p q r s t
>


On Nov 27, 2007 6:41 AM, Alexy Khrabrov <deliverable at gmail.com> wrote:
> Using wk <- with(d, split(word, kind)), I get the following class table:
>
> wk$`1`
> [1] "a" "bra" ...  # (*)
>
> wk$`10`
> "ca" "dabra" ...
>
> Now I need to export it in the following format:
>
> class    num_members   examples
> 1          23                       a bra ...
> 10        4                         ca dabra
>
> For each class C such as `1`, I need to print the number of members,
> length(wk[[C]]), and show N examples as sample(wk[[C]], N), space-
> separated.  The columns themselves are tab-separated.
>
> What's the R way to export such as list?
> Cheers,
> Alexy
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list