lapply is a function in R that returns a list of the same length as given argument X, each element of which is the result of applying given function to the corresponding element of X
Questions tagged [lapply]
3969 questions
1
vote
1 answer
R - Scrape multiple url and wirte each data url in different excel data sheets
I'm trying to scrape different URL and write data in the same Excel's file but in a single page for each URL.
My code is this:
#install.packages("rvest")
library(XLConnect)
library(rvest)
{
for(i in c("2086","2167","2204")) {
…

xuriguer
- 77
- 9
1
vote
1 answer
R iterate through list of dataframes to create new column
I have a list of dataframes DFList. For every dataframe in DFList i would like to create a new column X4.
Small Example
X1 <- c(1,2,3,"X","Y")
X2 <- c(100,200,130,120,150)
X3 <- c(1000,250,290,122,170)
DF1 <- data.frame(X1,X2,X3)
X1 <-…

Paul
- 656
- 1
- 8
- 23
1
vote
1 answer
Efficient way to create new column based on nested if else conditions and comparing values from lists in R
Input dt -
dt <- data.frame(a_check=c(1,2,1,1,2),
b_check=c(0,1,NA,1,15),
c_check=c(1,0,0,1,NA),
d_check=c(1,1,1,0,0),
e_check=c(1,NA,0,1,1))
Validation Lists-
valid_values <-…

Rushabh Patel
- 2,672
- 13
- 34
1
vote
1 answer
Recalculate each point in dataframe with lapply/sapply
I write my own function named batcheffect to recalculate all values in a dataframe.
The function only needs the dataframe as import. First, the mean is calculated in the function and then for each point in the dataframe the calculation is made and…

Lisann
- 5,705
- 14
- 41
- 50
1
vote
2 answers
various transformations with lapply() - R
I have this df:
df <- structure(list(Created = structure(6:1, .Label = c("2018-12-27T08:53:32.794-0300",
"2018-12-27T17:46:00.244-0300", "2019-01-17T17:16:08.222-0300",
"2019-01-28T11:52:39.744-0300", "2019-01-28T11:55:34.723-0300",…

Chris
- 2,019
- 5
- 22
- 67
1
vote
1 answer
scatter plot, colored by category variable, faceted over categorical variable in r
I have a data frame with a number of numeric and categorical variables.
data <- data.frame(dep_var = ...,
cat1 = ...,
cat2 = ...,
...
num1 = ...,
num2 = ...,
…

dedelman
- 11
- 2
1
vote
1 answer
t.test: create lapply function for multiple grouping levels
I'm trying to create an lapply function to run multiple t.tests for multiple levels of grouping. I came across this question: Kruskal-Wallis test: create lapply function to subset data.frame? but they were only trying to group by one variable…

TheSciGuy
- 1,154
- 11
- 22
1
vote
1 answer
Extracting Estimate and P-value from multiple cor.test() results in R
I have an Excel workbook with 54 sheets. Each sheet represents one country and is an 17 x 11 matrix where rows are years and columns are economic variables.
I can bring the Excel workbook into R using the readxl package.
sheet_list <- lapply(1:54,…

Savi
- 49
- 7
1
vote
1 answer
Write the output of a lapply call to a single table
I am using lapply in my data set as
dt <- read.table(text ="Year Premium Silver Budget
Jan2016 112354 36745 456563
Feb2016 1233445 234322 4533345
Mar2016 13456544 346755 34564422",…

AlisonGrey
- 497
- 1
- 7
- 23
1
vote
1 answer
rename columns in a list of dataframes
I need to be able to rename columns by name in a list of dataframes that can all expected to have the same names.
For example:
[[1]]
col1 col2
1 1 2
2 2 3
[[2]]
col1 col2
1 1 2
2 2 3
Should become:
[[1]]
ID col2
1 …

user1658170
- 814
- 2
- 14
- 24
1
vote
0 answers
lapply changes data undesirably
I am looking to apply an UDF to an entire dataframe via lapply. However, the act of doing so also coerces data in a way almost as if R wanted to dummy code the columns.
dummy data
df = data.frame(customer_id = c("c000000067", "c000678746")
…

Sweepy Dodo
- 1,761
- 9
- 15
1
vote
3 answers
Loop over function that has three arguments, mapply/sapply/for loops not working?
I am trying to loop over a function that has three arguments, but neither lapply nor mapply is providing the right solution. The goal here is to obtain all possible results based on all possible combinations of the three arguments (num, resp, cdr).…

rowbust
- 451
- 1
- 5
- 14
1
vote
1 answer
Error Converting Googleway outport to Dataframe
I have been utilizing code from the answer of a previous question with great success. Last night, after successfully using the code many times I started to receive an error when trying to execute the second part of the code to access list results.…

Rho
- 21
- 2
1
vote
1 answer
merge two table in R by by implicit columns
I have two tables
tab1=structure(list(generated_id = c(482160724447511, 482160724447511
), utc_time = structure(c(1L, 1L), .Label = "30.09.2018 12:46", class = "factor"),
local_time = structure(c(1L, 1L), .Label = "30.09.2018 15:46", class =…

Julia
- 141
- 11
1
vote
0 answers
st_difference to each feature in sf object
Data available here
I have 2 large sf objects. One is an sf polygon object of buffered points and the other is an sf line object. I would like to difference the line object using the polygon object like so:
library(sf)
geopackage =…

Josh J
- 395
- 1
- 3
- 13