do.call

do.call() doesn't like base function “c” with a list

亡梦爱人 提交于 2019-12-22 10:30:02
问题 I have a larger section of code but I've narrowed down the problem to this - So I want to return a concatenated list. do.call(c,"X") Error in do.call(c, "X") : second argument must be a list So above it complains about the SECOND argument not being a list. asimplelist=list(2,3,4) class(asimplelist) [1] "list" do.call(c,asimplelist) Error in do.call(c, asimplelist) : 'what' must be a function or character string Why will this not return a concatenated list ? C is a legit function, and it's

how to combine vectors with different length within a list in R?

一世执手 提交于 2019-12-21 01:40:13
问题 I have a problem when combining the following vectors included in the list: x <- list(as.numeric(c(1,4)),as.numeric(c(3,19,11))) names (x[[1]]) <- c("species.A","species.C") names (x[[2]]) <- c("species.A","species.B","species.C") which gives the following list: >x >[[1]] >species.A species.C > 1 4 >[[2]] >species.A species.B species.C > 3 19 11 combining them using the do.call function: y<- do.call(cbind,x) gives: >y > [,1] [,2] > species.A 1 3 > species.B 4 19 > species.C 1 11 while I would

Using do.call factor to scale - resetting value error

梦想与她 提交于 2019-12-12 04:57:43
问题 This is an extension of the question that I asked here: Getting Factor Means into the dataset after calculation Now that I have basically normalized all of the stats that I am interested in using I want to search the data set for people that intersect with these. Thus I am searching the dataset like this: base3[((base3$ScaledAVG>2)&(base3$ScaledOBP>2)&(base3$ScaledK.AB<.20)),] looking for the players that have all three of those things true, yet when I run this it resets the Scaled K.AB value

How do I pass every element of a list to a function as unnamed arguments?

风格不统一 提交于 2019-12-10 19:03:52
问题 Let's say I have some models stored in a list: mods <- list() mods[[1]] <- lm(mpg ~ disp, data = mtcars) mods[[2]] <- lm(mpg ~ disp + factor(cyl), data = mtcars) mods[[3]] <- lm(mpg ~ disp * factor(cyl), data = mtcars) And I want to compare them using stats::AIC . I'm looking for the output I would get from AIC(mods[[1]], mods[[2]], mods[[3]]) , but I'd like it to generalize to an arbitrarily long list. I thought that do.call(AIC, mods) would work, but it returns something that's very verbose

do.call and order to sort each row to descending order of a matrix?

大兔子大兔子 提交于 2019-12-09 13:46:23
问题 I want to sort this matrix row-wise to descending order > set.seed(123); a <- matrix(rbinom(100,10,0.3),ncol=10) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 2 6 5 6 1 1 4 4 2 1 [2,] 4 3 4 5 3 3 1 3 4 4 [3,] 3 4 3 4 3 4 3 4 3 2 [4,] 5 3 7 4 2 1 2 0 4 4 [5,] 5 1 4 0 2 3 4 3 1 2 [6,] 1 5 4 3 1 2 3 2 3 2 [7,] 3 2 3 4 2 1 4 2 6 4 [8,] 5 1 3 2 3 4 4 3 5 1 [9,] 3 2 2 2 2 5 4 2 5 3 [10,] 3 6 1 2 5 2 3 1 2 3 but > do.call(order,as.list(a[1,],a[2,])) [1] 1 How can you sort the matrix with

R - Ordering using do.call with descending order

旧巷老猫 提交于 2019-12-08 09:45:56
问题 I want to order a dataset based on an user input. The user input will be a char array (of column name), called cols below. dataset1[do.call('order', as.list(dataset1[cols])),] This works fine. I'm trying to add the ordering direction (descending or ascending) too but I keep getting the same error: "unused argument (descending = TRUE)". Anyone can help me setting the ordering direction while using a char[] of columns? 回答1: We can place the extra argument in a list , concatenate the dataset

plot() and do.call(): How to pass expressions to plot title when '…' is used otherwise?

岁酱吖の 提交于 2019-12-08 01:32:13
问题 When run the following code, I obtain Error in as.graphicsAnnot(text) : could not find function "bold" . How can I fix this? my.qq <- function(x, main=expression(bold(italic(F)~~"Q-Q plot")), margs=list(side=3, cex=par("cex.main"), font=par("font.main"), adj=par("adj"), xpd=NA), ...) { plot(qnorm(ppoints(n <- length(x))), sort(x), ...) do.call(mtext, c(list(main), margs)) } x <- rnorm(100) my.qq(x) my.qq(x, main=substitute(bold(italic(F)[N(mu.,s2.)]~~"Q-Q plot"), list(mu.=0, s2.=1))) # fails

Behavior of do.call() in the presence of arguments without defaults

試著忘記壹切 提交于 2019-12-07 08:37:07
问题 This question is a follow-up to a previous answer which raised a puzzle. Reproducible example from the previous answer: Models <- list( lm(runif(10)~rnorm(10)),lm(runif(10)~rnorm(10)),lm(runif(10)~rnorm(10)) ) lm1 <- lm(runif(10)~rnorm(10)) library(functional) # This works do.call( Curry(anova, object=lm1), Models ) # But so does this do.call( anova, Models ) The question is why does do.call(anova, Models) work fine, as @Roland points out? The signature for anova is anova(object, ...) anova

do.call and curve can not plot a function inside another function environment

匆匆过客 提交于 2019-12-06 11:20:13
问题 I am facing a strange problem about do.call and curve : func1 <- function (m, n) { charac <- paste ("func2 <- function(x)", m, "*x^", n, sep = "") eval(parse(text = charac)) return(func2) } func3 <- function (m, n) { my.func <- func1 (m, n) do.call("curve",list(expr = substitute(my.func))) } func1 constructs func2 and func3 plots the constructed func2 . But when I run func3 , following error would be displayed: > func3 (3, 6) Error in curve(expr = function (x) : 'expr' must be a function, or

do.call() doesn't like base function “c” with a list

 ̄綄美尐妖づ 提交于 2019-12-06 00:30:20
I have a larger section of code but I've narrowed down the problem to this - So I want to return a concatenated list. do.call(c,"X") Error in do.call(c, "X") : second argument must be a list So above it complains about the SECOND argument not being a list. asimplelist=list(2,3,4) class(asimplelist) [1] "list" do.call(c,asimplelist) Error in do.call(c, asimplelist) : 'what' must be a function or character string Why will this not return a concatenated list ? C is a legit function, and it's being passed a list? args(do.call) function (what, args, quote = FALSE, envir = parent.frame()) NULL So