lapply

How to dynamically list matrices as elements in a list in R [duplicate]

醉酒当歌 提交于 2021-01-28 19:53:19
问题 This question already has answers here : Make a list of many objects from a vector of object names [duplicate] (2 answers) Closed 6 months ago . This post is similar to my other post Let's say if I have 4 matrices: x1 <- matrix(1:9, nrow = 3) x2 <- matrix(2:10, nrow = 3) x3 <- matrix(3:11, nrow = 3) x4 <- matrix(4:12, nrow = 3) And I want to put them into a list() in a way like this: [[1]] [[1]][[1]] [,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 [[1]][[2]] [,1] [,2] [,3] [1,] 2 5 8 [2,] 3 6

R: how to find select files in a folder based on matching specific column title

自古美人都是妖i 提交于 2021-01-28 13:37:52
问题 Sorry for the generic question. I'm looking for pointers for sorting out a data folder, in which I have numerous .txt files. All of them have different titles, and for the vast majority of them, the files have the same dimension, that is the column numbers are the same. However, the pain is some of the files, despite having the same number of columns, have different column names. That is in those files, some other variables were measured. I want to weed out these files, and I cannot do by

R: how to find select files in a folder based on matching specific column title

一世执手 提交于 2021-01-28 13:34:39
问题 Sorry for the generic question. I'm looking for pointers for sorting out a data folder, in which I have numerous .txt files. All of them have different titles, and for the vast majority of them, the files have the same dimension, that is the column numbers are the same. However, the pain is some of the files, despite having the same number of columns, have different column names. That is in those files, some other variables were measured. I want to weed out these files, and I cannot do by

R: how to find select files in a folder based on matching specific column title

回眸只為那壹抹淺笑 提交于 2021-01-28 13:33:35
问题 Sorry for the generic question. I'm looking for pointers for sorting out a data folder, in which I have numerous .txt files. All of them have different titles, and for the vast majority of them, the files have the same dimension, that is the column numbers are the same. However, the pain is some of the files, despite having the same number of columns, have different column names. That is in those files, some other variables were measured. I want to weed out these files, and I cannot do by

Apply factor levels to multiple columns with missing factor levels

无人久伴 提交于 2021-01-28 10:45:45
问题 I have a dataframe with many factors and want to create statistical tables that show the distribution for each factor, including factor levels with zero observations. For instance, these data: structure(list(engag11 = structure(c(5L, 4L, 4L), .Label = c("Strongly Disagree", "Disagree", "Neither A or D", "Agree", "Strongly Agree"), class = "factor"), encor11 = structure(c(1L, 1L, 1L), .Label = c("Agree", "Neither Agree or Disagree", "Strongly Agree"), class = "factor"), know11 = structure(c(3L

Apply factor levels to multiple columns with missing factor levels

懵懂的女人 提交于 2021-01-28 10:42:24
问题 I have a dataframe with many factors and want to create statistical tables that show the distribution for each factor, including factor levels with zero observations. For instance, these data: structure(list(engag11 = structure(c(5L, 4L, 4L), .Label = c("Strongly Disagree", "Disagree", "Neither A or D", "Agree", "Strongly Agree"), class = "factor"), encor11 = structure(c(1L, 1L, 1L), .Label = c("Agree", "Neither Agree or Disagree", "Strongly Agree"), class = "factor"), know11 = structure(c(3L

Matching strings loop over multiple columns

百般思念 提交于 2021-01-28 01:41:19
问题 I have data from an open ended survey. I have a comments table and a codes table. The codes table is a set of themes or strings. What I am trying to do: Check to see if a word / string exists from the relevant column in the codes table is in an open ended comment. Add a new column in the comments table for the specific theme and a binary 1 or 0 to denote what records have been tagged. There are quite a number of columns in the codes table, these are live and ever changing, column orders and

How to names lists under list when using lapply?

故事扮演 提交于 2021-01-27 21:57:42
问题 I have a two nested loop which I want to do it with lapply instead of for loops. I have made up the following simple example: a<-as.list(c(1,2)) b<-as.list(c(6,7)) results<-lapply(a, function(x) lapply(b, function(y) x+y)) > results [[1]] [[1]][[1]] [1] 7 [[1]][[2]] [1] 8 [[2]] [[2]][[1]] [1] 8 [[2]][[2]] [1] 9 how can I assign names to this list, I can assign names to the first level using names(result)<-a, but I do not know how to do it for the second level. And naming should be done in

How to loop through objects in the global environment - R

和自甴很熟 提交于 2021-01-03 06:59:50
问题 I have looked far and wide for a solution to this issue, but I cannot seem to figure it out. I do not have much experience working with xts objects in R. I have 40 xts objects (ETF data) and I want to run the quantmod function WeeklyReturn on each of them individually. I have tried to refer to them by using the ls() function: lapply(ls(), weeklyReturn) I have also tried the object() function lapply(object(), weeklyReturn) I have also tried using as.xts() in my call to coerce the ls() objects

How to loop through objects in the global environment - R

纵饮孤独 提交于 2021-01-03 06:59:15
问题 I have looked far and wide for a solution to this issue, but I cannot seem to figure it out. I do not have much experience working with xts objects in R. I have 40 xts objects (ETF data) and I want to run the quantmod function WeeklyReturn on each of them individually. I have tried to refer to them by using the ls() function: lapply(ls(), weeklyReturn) I have also tried the object() function lapply(object(), weeklyReturn) I have also tried using as.xts() in my call to coerce the ls() objects