lapply

Run linear models by group over list of variables in R

送分小仙女□ 提交于 2020-08-20 07:38:39
问题 I have a data frame and I need to run 6 2-variable linear models for each group 'site'. Then, I need to convert the results to a data frame. The second variable in the linear model changes. I have that part down using lapply() , but I can't figure out how to run by groups. I've found answers on SO that answer parts of my question, but I can't figure out how to put it all together. Here's some data: structure(list(SiteName = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(

Run linear models by group over list of variables in R

你。 提交于 2020-08-20 07:37:25
问题 I have a data frame and I need to run 6 2-variable linear models for each group 'site'. Then, I need to convert the results to a data frame. The second variable in the linear model changes. I have that part down using lapply() , but I can't figure out how to run by groups. I've found answers on SO that answer parts of my question, but I can't figure out how to put it all together. Here's some data: structure(list(SiteName = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(

cbind two lists of data.frames to a new list [duplicate]

南楼画角 提交于 2020-08-19 04:36:37
问题 This question already has an answer here : Combine two lists of dataframes, dataframe by dataframe (1 answer) Closed 5 years ago . I have two lists of data.frames. Both lists have the same length and contain fitting data.frames in their according list elements. So the scenario looks like this dfa = data.frame(a=1:3, b = letters[1:3]) dfb = data.frame(x=runif(3)) a = replicate(3, dfa, simplify = FALSE) b = replicate(3, dfb, simplify = FALSE) One obvious solution is: lapply(seq_along(a),

How to read multiple .xls files in r?

半腔热情 提交于 2020-08-12 00:18:46
问题 I have 18 files(.xls) in list and I want to read them in one go Here is my codes below: filenames=list.files("C:/Users/ozgur.alptekin/Downloads/elif") df.list=lapply(filenames, function(x) read_excel(file = x,sheetIndex = 1,as.data.frame = TRUE,header = TRUE)) it did not work Could you please tell me what I have done wrong and how I should do it? 回答1: Can you simply try a loop? filenames=list.files("C:/Users/ozgur.alptekin/Downloads/elif") for (i in 1:length(filenames) { assign(paste0("file_"

How to read multiple .xls files in r?

一世执手 提交于 2020-08-12 00:09:42
问题 I have 18 files(.xls) in list and I want to read them in one go Here is my codes below: filenames=list.files("C:/Users/ozgur.alptekin/Downloads/elif") df.list=lapply(filenames, function(x) read_excel(file = x,sheetIndex = 1,as.data.frame = TRUE,header = TRUE)) it did not work Could you please tell me what I have done wrong and how I should do it? 回答1: Can you simply try a loop? filenames=list.files("C:/Users/ozgur.alptekin/Downloads/elif") for (i in 1:length(filenames) { assign(paste0("file_"

How to read multiple .xls files in r?

試著忘記壹切 提交于 2020-08-12 00:06:50
问题 I have 18 files(.xls) in list and I want to read them in one go Here is my codes below: filenames=list.files("C:/Users/ozgur.alptekin/Downloads/elif") df.list=lapply(filenames, function(x) read_excel(file = x,sheetIndex = 1,as.data.frame = TRUE,header = TRUE)) it did not work Could you please tell me what I have done wrong and how I should do it? 回答1: Can you simply try a loop? filenames=list.files("C:/Users/ozgur.alptekin/Downloads/elif") for (i in 1:length(filenames) { assign(paste0("file_"

How to read multiple .xls files in r?

杀马特。学长 韩版系。学妹 提交于 2020-08-12 00:05:47
问题 I have 18 files(.xls) in list and I want to read them in one go Here is my codes below: filenames=list.files("C:/Users/ozgur.alptekin/Downloads/elif") df.list=lapply(filenames, function(x) read_excel(file = x,sheetIndex = 1,as.data.frame = TRUE,header = TRUE)) it did not work Could you please tell me what I have done wrong and how I should do it? 回答1: Can you simply try a loop? filenames=list.files("C:/Users/ozgur.alptekin/Downloads/elif") for (i in 1:length(filenames) { assign(paste0("file_"

How to extract marginal means of multiple variables with effect() function?

你离开我真会死。 提交于 2020-08-09 07:47:07
问题 I'm a beginner of R, and I would like to perform ANCOVA in a dataset with over 200 columns of outcome variables. The most important thing for me is to extract both p values and marginal means of these variables. I successfully extracted p values with the help of lapply() function, but when I extracted marginal means I got such error Error in eval(predvars, data, env) : object 'x' not found . Here I use the built-in dataset "iris" as an example to display my problem. data("iris") #load