lapply

R multiple functions into lapply

南笙酒味 提交于 2020-12-29 12:59:49
问题 I have a list of urls in a character vector and I want to pause the process between queries because if not the x queries is rejected. urls=c('url1','url2','url3') here is want I want to do htmlpages=lapply(urls,function(x) readLines(x) Sys.sleep(0.3)) 回答1: As Justin suggested, formatting is the key. htmlpages = lapply( urls, function(x) { y <- readLines(x) Sys.sleep(0.3) y } ) 来源: https://stackoverflow.com/questions/20473952/r-multiple-functions-into-lapply

R multiple functions into lapply

梦想的初衷 提交于 2020-12-29 12:58:27
问题 I have a list of urls in a character vector and I want to pause the process between queries because if not the x queries is rejected. urls=c('url1','url2','url3') here is want I want to do htmlpages=lapply(urls,function(x) readLines(x) Sys.sleep(0.3)) 回答1: As Justin suggested, formatting is the key. htmlpages = lapply( urls, function(x) { y <- readLines(x) Sys.sleep(0.3) y } ) 来源: https://stackoverflow.com/questions/20473952/r-multiple-functions-into-lapply

Apply a user defined function to a list of data frames

淺唱寂寞╮ 提交于 2020-12-15 06:37:20
问题 I have a series of data frames structured similarly to this: df <- data.frame(x = c('notes','year',1995:2005), y = c(NA,'value',11:21)) df2 <- data.frame(x = c('notes','year',1995:2005), y = c(NA,'value',50:60)) In order to clean them I wrote a user defined function with a set of cleaning steps: clean <- function(df){ colnames(df) <- df[2,] df <- df[grep('^[0-9]{4}', df$year),] return(df) } I'd now like to put my data frames in a list: df_list <- list(df,df2) and clean them all at once. I

Performing a linear model in R of a single response with a single predictor from a large dataframe and repeat for each column

99封情书 提交于 2020-12-15 01:47:19
问题 It might not be very clear from the title but what I wish to do is: I have a dataframe df with, say, 200 columns and the first 80 columns are response variables (y1, y2, y3, ...) and the rest of 120 are predictors (x1, x2, x3, ...). I wish to compute a linear model for each pair – lm(yi ~ xi, data = df) . Many problems and solutions I have looked through online have a either a fixed response vs many predictors or the other way around, using lapply() and its related functions. Could anyone who

Performing a linear model in R of a single response with a single predictor from a large dataframe and repeat for each column

血红的双手。 提交于 2020-12-15 01:44:08
问题 It might not be very clear from the title but what I wish to do is: I have a dataframe df with, say, 200 columns and the first 80 columns are response variables (y1, y2, y3, ...) and the rest of 120 are predictors (x1, x2, x3, ...). I wish to compute a linear model for each pair – lm(yi ~ xi, data = df) . Many problems and solutions I have looked through online have a either a fixed response vs many predictors or the other way around, using lapply() and its related functions. Could anyone who

Using apply functions with ggplot to plot a subset of dataframe columns

丶灬走出姿态 提交于 2020-12-14 23:41:55
问题 I have a dataframe df with many columns ... I'd like plot of subset of columns where c is a list of the columns I'd like to plot. I'm currently doing the following df <-structure(list(Image.Name = structure(1:5, .Label = c("D1C1", "D2C2", "D4C1", "D5C3", "D6C2"), class = "factor"), Experiment = structure(1:5, .Label = c("020718 perfusion EPC_BC_HCT115_Day 5", "020718 perfusion EPC_BC_HCT115_Day 6", "020718 perfusion EPC_BC_HCT115_Day 7", "020718 perfusion EPC_BC_HCT115_Day 8", "020718

Using apply functions with ggplot to plot a subset of dataframe columns

99封情书 提交于 2020-12-14 23:39:26
问题 I have a dataframe df with many columns ... I'd like plot of subset of columns where c is a list of the columns I'd like to plot. I'm currently doing the following df <-structure(list(Image.Name = structure(1:5, .Label = c("D1C1", "D2C2", "D4C1", "D5C3", "D6C2"), class = "factor"), Experiment = structure(1:5, .Label = c("020718 perfusion EPC_BC_HCT115_Day 5", "020718 perfusion EPC_BC_HCT115_Day 6", "020718 perfusion EPC_BC_HCT115_Day 7", "020718 perfusion EPC_BC_HCT115_Day 8", "020718

Using apply functions with ggplot to plot a subset of dataframe columns

为君一笑 提交于 2020-12-14 23:37:20
问题 I have a dataframe df with many columns ... I'd like plot of subset of columns where c is a list of the columns I'd like to plot. I'm currently doing the following df <-structure(list(Image.Name = structure(1:5, .Label = c("D1C1", "D2C2", "D4C1", "D5C3", "D6C2"), class = "factor"), Experiment = structure(1:5, .Label = c("020718 perfusion EPC_BC_HCT115_Day 5", "020718 perfusion EPC_BC_HCT115_Day 6", "020718 perfusion EPC_BC_HCT115_Day 7", "020718 perfusion EPC_BC_HCT115_Day 8", "020718

Using apply functions with ggplot to plot a subset of dataframe columns

故事扮演 提交于 2020-12-14 23:36:56
问题 I have a dataframe df with many columns ... I'd like plot of subset of columns where c is a list of the columns I'd like to plot. I'm currently doing the following df <-structure(list(Image.Name = structure(1:5, .Label = c("D1C1", "D2C2", "D4C1", "D5C3", "D6C2"), class = "factor"), Experiment = structure(1:5, .Label = c("020718 perfusion EPC_BC_HCT115_Day 5", "020718 perfusion EPC_BC_HCT115_Day 6", "020718 perfusion EPC_BC_HCT115_Day 7", "020718 perfusion EPC_BC_HCT115_Day 8", "020718

Merging multiple .xls files in R [duplicate]

北战南征 提交于 2020-12-13 04:14:34
问题 This question already has answers here : How to import multiple .csv files at once? (13 answers) How can I read multiple (excel) files into R? [duplicate] (1 answer) Closed last year . I am trying to merge a list of .xls files in google drive. I have now managed to create a list of all the files I need, but for some reason I still can't manage to merge them, this is the code I have so far: library(googledrive) inputfiles <- drive_ls(path = "Email It In", pattern = "*PDOL_dataexport", n_max =