do.call

calling grid.arrange on a list of ggplots

China☆狼群 提交于 2021-01-28 00:37:09
问题 This question is linked to this one here: Related post My present question is: In my code I generate a list of ggplots in a list by calling lapply. I use lapply in the first place because I execute a fairly big amount of similar ggplots and it would be too cumbersome to generate each ggplots manually. how can I generalize my code? p <- qplot(rnorm(30)) plist <- lapply(c(1:10),FUN=function(x){ qplot(rnorm(30)) }) #works year.plots <- list(p,p) do.call(grid.arrange, c(year.plots)) #works plist[

R: Error in pi[[j]] : subscript out of bounds — rbind on a list of dataframes

前提是你 提交于 2021-01-02 07:57:32
问题 I am trying to rbind a large list of data frames (outputDfList), which is generated by lapply a complicated function to a large table. You can recreate outputDfList by: df1=data.frame("randomseq_chr15q22.1_translocationOrInsertion", "chr15", "63126742") names(df1)=NULL df2=df1=data.frame("chr18q12.1_chr18q21.33_large_insertion", "chr18 ", "63126741") names(df2)=NULL outputDfList=list(df1,df2) my code is do.call(rbind, outputDfList) The error message I received: Error in pi[[j]] : subscript

R: Combine list of data frames into single data frame, add column with list index

坚强是说给别人听的谎言 提交于 2020-12-29 12:13:19
问题 The question is very similar to this one . It is for combining a list of data frames into a single longer data frame. However, I want to keep the information from which item of the list the data came from by adding an extra column with the index (id or source) of the list. This is the data (borrowing code from the linked example): dfList <- NULL set.seed(1) for (i in 1:3) { dfList[[i]] <- data.frame(a=sample(letters, 5, rep=T), b=rnorm(5), c=rnorm(5)) } Using the code below provides a

R: Combine list of data frames into single data frame, add column with list index

怎甘沉沦 提交于 2020-12-29 12:06:20
问题 The question is very similar to this one . It is for combining a list of data frames into a single longer data frame. However, I want to keep the information from which item of the list the data came from by adding an extra column with the index (id or source) of the list. This is the data (borrowing code from the linked example): dfList <- NULL set.seed(1) for (i in 1:3) { dfList[[i]] <- data.frame(a=sample(letters, 5, rep=T), b=rnorm(5), c=rnorm(5)) } Using the code below provides a

Merge multiple .csv files into one [duplicate]

血红的双手。 提交于 2020-02-20 11:21:48
问题 This question already has answers here : How to import multiple .csv files at once? (12 answers) Closed 2 years ago . I am aware this question has been asked multiple times, but despite of trying to apply the aforementioned solutions i was not able to solve my little problem: I have saved all my .csv that i am aiming to merge into one folder: > file_list <- list.files() > file_list[] [1] "SR-einfam.csv" "SR-garage.csv" "SR-hotel.csv" [4] "SR-IndustrieGewerbe.csv" "SR-mehrfam.csv" "SR-OffG.csv

do.call specify environment inside function

萝らか妹 提交于 2020-01-22 12:34:07
问题 I'm using the following construct in a package, ## two functions in the global environment funa <- function(x) x^2 funb <- function(x) x^3 ## called within a function, fine fun_wrap <- function(){ lapply(c('funa', 'funb'), do.call, list(x=3)) } fun_wrap() [[1]] [1] 9 [[2]] [1] 27 but I've just been bitten by the fact that it won't work if the functions are in a different (local) frame, ## same construct, but the functions are local fun_wrap1 <- function(){ funa1 <- function(x) x^2 funb1 <-

Why a row of my matrix is a list? R

六月ゝ 毕业季﹏ 提交于 2020-01-17 07:23:27
问题 I got a list of matrices X rows by 2 columns, called list_of_matrices_by2 list_of_matrices_by2[1:3] [[1]] [,1] [,2] [1,] "7204" "d" [2,] "7204" "a" [[2]] [,1] [,2] [1,] "2032" "b" [2,] "2032" "e" [3,] "2032" "a" [[3]] [,1] [,2] [1,] "802" "d" [2,] "802" "b" I want to stack all my matrices in a all_pairs matrix, so I did this all_pairs=do.call(rbind,list_of_matrices_by2) all_pairs[1:10] [,1] [,2] [1,] "7204" "d" [2,] "7204" "a" [3,] "2032" "b" [4,] "2032" "e" [5,] "2032" "a" [6,] "802" "d" [7,

how to add more arguments of a function in do.call in R

孤人 提交于 2020-01-15 01:24:50
问题 My question is how I might be able to add more arguments to the do.call function. For example, I want to draw faceted grid plots with grid.arrange , how can I add more arguments such as ncol=3 and main="main title" to the command do.call(grid.arrange,plots) ? 回答1: consider this list of plots, library(ggplot2) library(gridExtra) pl = replicate(5, qplot(1,1), simplify = FALSE) you can combine it with a list of options to be passed to do.call , do.call(grid.arrange, c(pl, list(ncol=5, main=

Duplicate the rows based on some criteria in SQL or R

…衆ロ難τιáo~ 提交于 2020-01-01 17:09:19
问题 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

Using cbind on an arbitrarily long list of objects

元气小坏坏 提交于 2019-12-28 02:58:29
问题 I would like to find a way to create a data.frame by using cbind() to join together many separate objects. For example, if A, B, C & D are all vectors of equal length, one can create data.frame ABCD with ABCD <- cbind(A,B,C,D) However, when the number of objects to be combined gets large, it becomes tedious to type out all of their names. Furthermore, Is there a way to call cbind() on a vector of object names, e.g. objs <- c("A", "B", "C", "D") ABCD <- cbind(objs) or on a list containing all