Hello thanks everyone for your help i managed to get a working function as
followed:
for(i in 2:length(list_df)){
list_df[[paste0("position_tab_",i)]][['ID']] <-
unlist(lapply(list_df[[paste0("position_tab_",i)]][['midpoint']],
function(x)
ifelse(any(abs(x - list_df[[paste0("position_tab_",i-1)
Perhaps the following will be helpful (you can ignore the warning message
here):
> set.seed(1001)
> x <- sample(1:5,10, rep = TRUE)
> y <- sample(1:5,12, rep = TRUE)
> n <- seq_len(min(length(x), length(y)))
> flag <- as.numeric(abs(x-y)[n] <= 1)
Warning message:
In x - y : longer object length is
*I hope this is more succinct.*
*I have the following code: *
list_df$position_tab_5$ID <- unlist(lapply(list_df$position_tab_5$midpoint,
function(x) ifelse(any(abs(x - list_df$position_tab_4$midpoint) <= 1),1,0)))
It compares every observation from the midpoint column from dataframe 2 to
every
Hi Kathan,
How about trying to create a *minimal* reproducible example, e.g. with a
list of two data frames, where each data frame has 5 rows,?
My guess is that there is a good chance that when you try to create such an
example, you will discover the problem yourself.
In the event that you create t
-- Forwarded message -
From: Kathan Desai
Date: Sat, 4 Jul 2020 at 14:31
Subject: Re: [R] Help with looping a function over a list of dataframes:
To: Jim Lemon
Hi Jim,
Thankyou for your reply, I tried the function you suggested and it
doesn't seem to work. There are again no er
5 matches
Mail list logo