[英]R: Remove Rows From Data Frame [i] of List 1 based on Index values from Data Frame [j] of List 2
I have the following problem:我有以下问题:
I have one list of data frames that includes a heart rate signal for each participant.我有一个数据帧列表,其中包含每个参与者的心率信号。 Furthermore, I have a list of data frames which include the index values of outliers, which I want to remove.
此外,我有一个数据框列表,其中包含我想要删除的异常值的索引值。 What I want to do is to write a function, which removes outliers from the HR signal of participant 1 in List 1 based on Index values from outlier index values of participant 1 in List 2, and get an output list of cleaned HR signal without the indexed outliers.
我想要做的是编写一个 function,它根据列表 2 中参与者 1 异常值索引值的索引值从列表 1 中参与者 1 的 HR 信号中删除异常值,并得到一个 output 清洁 HR 信号列表索引异常值。 In other words, I want to remove rows in Element[i] in List 1 based on the index values of Element[i] in list 2.
换句话说,我想根据列表 2 中 Element[i] 的索引值删除列表 1 中 Element[i] 中的行。
Example Code and Description:示例代码和说明:
HR = list(df1, df2, df3, df4, df5) # list of data frames each containing one heart rate signal
outlier_list = list(df1, df2, df3, df4, df5) # list of data frames each cointaining the index values of the corresponding particiapant, which I want to remove --> e.g. HR$df1 & outlier_list$df1 contain values for participant 1
# I tried the following:
HR_clean = lapply(HR, function(x){ lapply(outlier_list, function(i){
x[-c(i)]})
})
Unfortunately the HR_clean output does not yield any useful result.不幸的是,HR_clean output 没有产生任何有用的结果。
I hope it is clear what I am trying to achieve.我希望很清楚我想要达到的目标。 I am grateful for any tips!!
我很感激任何提示!
Based on the description, it should not be a nested loop.根据描述,它不应该是嵌套循环。 Instead, this should be done on corresponding elements and it is easier with
Map
相反,这应该在相应的元素上完成,使用
Map
更容易
Map(function(dat, i) dat[-i], HR, outlier_list)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.