do.call

How to avoid renaming of rows when using rbind inside do.call?

元气小坏坏 提交于 2019-12-05 21:28:10
问题 I am trying to bind some sub elements of the elements from the list The list OC is as follows > library(quantmod) > OC <- getOptionChain('AAPL', NULL) > str(OC) List of 9 $ Feb 2013:List of 3 ..$ calls :'data.frame': 35 obs. of 7 variables: .. ..$ Strike: num [1:35] 380 390 400 410 420 430 440 445 450 455 ... .. ..$ Last : num [1:35] 89.9 86 60 49.5 39.8 ... .. ..$ Chg : num [1:35] 0 0 -0.4 -4.4 -0.7 -1.9 -0.55 -0.7 -0.95 -1 ... .. ..$ Bid : num [1:35] 79.5 69.8 59.8 49.8 39.6 ... .. ..$ Ask

How to combine do.call() plot() and expression()

浪子不回头ぞ 提交于 2019-12-05 14:38:16
问题 I am getting an error when I try and combine using expression with do.call and plot . x <- 1:10 y <- x^1.5 I can get the plot I want by using only the plot function: plot(y~x,xlab=expression(paste("Concentration (",mu,"M)"))) However, I would like to implement my plot using do.call . I have a really long list of parameters stored as a list, p . However, when I try and pass the list to do.call I get the following error: p <- list(xlab=expression(paste("Concentration (",mu,"M)"))) do.call(plot

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

元气小坏坏 提交于 2019-12-05 13:14:18
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 calls UseMethod , which should* call anova.lm which should call anova.lmlist , whose first line is

Duplicate the rows based on some criteria in SQL or R

大憨熊 提交于 2019-12-04 19:20:33
I use R to generate a toy set data.frame(name = c("Tom", "Shane", "Daniel", "Akira", "Jack", "Zoe"), c1 = c(1,2,3,0,5,0), c2 = c(0, 3, 5, 0,4,0), c3 = c(0, 0,1,0,0,3), c4=c(0,0,0,1,0,0)) which is displayed below: I only care about the columns c1, c2, c3, c4 , and if a specific row has more than one value, which is greater than 0. we need to duplicate rows to make sure that there are only one value, which is greater than 0, and then remove the original row. For instance, the second row has two values are greater than 0 (c1: 2, c2: 3), then we have to duplicate that row to two, which looks like

merging multiple csv files in R using do.call

冷暖自知 提交于 2019-12-04 19:16:13
问题 I am trying to import and merge a set of csv files using the following code, but it doesn't seem to be passing the by=c("X","Y") argument to the merge function. Any recommendations on how to fix this? Thank you csvfiles <- list.files(path = ".", pattern='bbg_.*\\.csv$') csvfiles <- paste("fx/",csvfiles,sep="") csvfiles my.df <- do.call("merge",list(lapply(csvfiles, read.csv, header = TRUE), by=c("date","fx_code"))) 回答1: merge doesn't accept more than 2 data.frames, so you can't pass it a

How to combine do.call() plot() and expression()

落花浮王杯 提交于 2019-12-04 00:32:03
I am getting an error when I try and combine using expression with do.call and plot . x <- 1:10 y <- x^1.5 I can get the plot I want by using only the plot function: plot(y~x,xlab=expression(paste("Concentration (",mu,"M)"))) However, I would like to implement my plot using do.call . I have a really long list of parameters stored as a list, p . However, when I try and pass the list to do.call I get the following error: p <- list(xlab=expression(paste("Concentration (",mu,"M)"))) do.call(plot,c(y~x,p)) Error in paste("Concentration (", mu, "M)") : object 'mu' not found I also tried defining the

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

戏子无情 提交于 2019-12-03 20:28:16
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 the do.call and order? Edit. Fixed above matrix to conform with the above code. Two alternatives: # Jaap

merging multiple csv files in R using do.call

拟墨画扇 提交于 2019-12-03 11:47:02
I am trying to import and merge a set of csv files using the following code, but it doesn't seem to be passing the by=c("X","Y") argument to the merge function. Any recommendations on how to fix this? Thank you csvfiles <- list.files(path = ".", pattern='bbg_.*\\.csv$') csvfiles <- paste("fx/",csvfiles,sep="") csvfiles my.df <- do.call("merge",list(lapply(csvfiles, read.csv, header = TRUE), by=c("date","fx_code"))) merge doesn't accept more than 2 data.frames, so you can't pass it a larger list using do.call : do.call(merge, list(iris, iris, iris)) #Error in fix.by(by.x, x) : # 'by' must

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

别说谁变了你拦得住时间么 提交于 2019-12-03 07:43:41
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 like to obtain this: > [,1] [,2] > species.A 1 3 > species.B NA 19 > species.C 4 11 You need to give R

Selecting rows from a data frame from combinations of lists [duplicate]

雨燕双飞 提交于 2019-12-02 19:32:32
问题 This question already has answers here : Removing one table from another in R [closed] (3 answers) Closed 2 years ago . I have a dataframe, dat: dat<-data.frame(col1=rep(1:4,3), col2=rep(letters[24:26],4), col3=letters[1:12]) I want to filter dat on two different columns using ONLY the combinations given by the rows in the data frame filter : filter<-data.frame(col1=1:3,col2=NA) lists<-list(list("x","y"),list("y","z"),list("x","z")) filter$col2<-lists So for example, rows containing (1,x) and