[R] mapply then export

R. Michael Weylandt michael.weylandt at gmail.com
Tue Nov 15 06:20:18 CET 2011


Perhaps something like:

sapply(1:40, function(n) c(gauss.quad(n)$nodes, rep(NA, 40-n)))
sapply(1:40, function(n) c(gauss.quad(n)$weights, rep(NA, 40-n)))

You'll have to decide how you want the records combined but this
should get you going in the right direction

Michael

PS -- it's polite to say what package your functions are coming from
so we don't have to hunt them down. Also, it's much more helpful to
have code that doesn't work rather than the vague "I've tried using
mapply but ..." because it allows us to give you pointers that relate
directly to your problem (and to your general coding style if there's
anything that can be cleaned up there -- there are some real R ninjas
on this list and I love watching their tricks)

On Mon, Nov 14, 2011 at 6:51 PM, RisConfusingMe
<derrick.kaufman at gmail.com> wrote:
> To use the gauss.quad function:  gauss.quad(n,type)  which returns two lists
> $nodes and $weights whose length will each equal n.  I'd like to do this for
> n=1 to 40 (type will not change) and have a dataset with 40 rows and 81
> columns with all the nodes and weights.  The first record would have N1 and
> W1 only and N2--N40 and W2--W40 would be missing.  The last record would be
> full.  I've tried using mapply but it returns something like this:
>
>
>        [,1] [,2]      [,3]      [,4]      [,5]      [,6]      [,7]
> nodes   1    Numeric,2 Numeric,3 Numeric,4 Numeric,5 Numeric,6 Numeric,7
> weights 1    Numeric,2 Numeric,3 Numeric,4 Numeric,5 Numeric,6 Numeric,7
>
>
> I have no idea how to get this into a format I can export and later use.
>
> Thanks for your help.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/mapply-then-export-tp4041345p4041345.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list