Mean of each row of data.frames column nested in list
Tag : r , By : Luciano Campos
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Extract the column, cbind the data.frames, and calculate the row means: rowMeans(do.call(cbind, lapply(ls1, "[", "x")))
|
Assign column names of data.frames in a list of data.frames to other (Spatial) data.frames in a list of data.frames in R
Date : March 29 2020, 07:55 AM
Hope that helps You had the right idea - I changed your function a bit and it should work now: changeCOL <- function(x, y){
names(y) <- names(x)
return(y)
}
test<-mapply(changeCOL,x=list_DF,y=listofSpatialDF)
# Test to show the names are the same now
names(test[[1]])==names(list_DF[[1]])
[1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
|
r remove outliers from a list of data.frames and make a new list of data.frames?
Tag : r , By : Stephen Judge
Date : March 29 2020, 07:55 AM
To fix the issue you can do Give this a shot. First I create data which I split into six data frames which are housed in a list. set.seed(0)
test_data <- data.frame(id = 1:10000,
T_C = sample(c(TRUE, FALSE), size = 10000, replace = TRUE),
Sales = rnorm(n = 10000),
grp = sample(c("a", "b", "c", "d", "e", "f"),
size = 10000, replace = TRUE))
test_split <- split(test_data, test_data$grp)
library(dplyr)
outlier_list <- lapply(test_split,
function(m) group_by(m, T_C) %>% mutate(z_score = (Sales - mean(Sales)) / sd(Sales)) %>%
ungroup() %>% filter(abs(z_score) >= 3)
)
> outlier_list
$a
# A tibble: 5 × 5
id T_C Sales grp z_score
<int> <lgl> <dbl> <fctr> <dbl>
1 468 TRUE -2.995332 a -3.073314
2 3026 TRUE 3.028495 a 3.075258
3 5188 TRUE -3.097847 a -3.177952
4 7993 FALSE -3.571076 a -3.823983
5 9105 TRUE -3.216710 a -3.299276
$b
# A tibble: 6 × 5
id T_C Sales grp z_score
<int> <lgl> <dbl> <fctr> <dbl>
1 264 TRUE 3.003494 b 3.003329
2 2172 TRUE 3.001475 b 3.001326
3 2980 FALSE -3.176356 b -3.222782
4 3366 FALSE 3.009292 b 3.048559
5 7477 FALSE 3.348301 b 3.392265
6 7583 TRUE -3.089758 b -3.040911
$c
# A tibble: 2 × 5
id T_C Sales grp z_score
<int> <lgl> <dbl> <fctr> <dbl>
1 8078 TRUE 3.015343 c 3.129923
2 8991 FALSE 3.113526 c 3.058302
$d
# A tibble: 5 × 5
id T_C Sales grp z_score
<int> <lgl> <dbl> <fctr> <dbl>
1 544 TRUE 3.289070 d 3.168235
2 3791 FALSE 3.791938 d 3.769810
3 6771 FALSE -3.157741 d -3.166861
4 7864 TRUE 3.164128 d 3.045728
5 9371 TRUE -3.026884 d -3.024655
$e
# A tibble: 6 × 5
id T_C Sales grp z_score
<int> <lgl> <dbl> <fctr> <dbl>
1 186 FALSE 3.021541 e 3.046079
2 1211 TRUE 3.414337 e 3.343521
3 1665 TRUE 3.546282 e 3.473614
4 3765 FALSE 3.363641 e 3.391142
5 4172 TRUE 3.348820 e 3.278923
6 7973 FALSE -2.987790 e -3.015284
$f
# A tibble: 6 × 5
id T_C Sales grp z_score
<int> <lgl> <dbl> <fctr> <dbl>
1 1089 TRUE -3.195090 f -3.189979
2 2452 FALSE 3.287591 f 3.212317
3 3486 FALSE -3.334942 f -3.367962
4 4198 FALSE -3.102578 f -3.137082
5 8183 TRUE 3.081077 f 3.075324
6 8656 TRUE 3.253873 f 3.247822
inlier_list <- lapply(test_split,
function(m) group_by(m, T_C) %>%
mutate(z_score = (Sales - mean(Sales)) / sd(Sales)) %>%
ungroup() %>% filter(abs(z_score) < 3)
)
wilcox_test_res <- lapply(inlier_list,
function(m) wilcox.test(m$Sales ~ m$T_C,
mu= mean(m$Sales[m$T_C == TRUE]),
conf.level=0.95,
|
Remove specific duplicated observations in data.frames from a list of data.frames
Tag : r , By : user119413
Date : March 29 2020, 07:55 AM
wish helps you I have a list of data.frames that looks like this: , If this is only related to "R4" values, then df[!((duplicated(df$Val) | duplicated(df$Val, fromLast=TRUE)) &
df$Val[df$Replicate == "R4"]), ]
mynonDupeList <- lapply(myList,
function(i) i[!((duplicated(df$Val) | duplicated(i$Val, fromLast=TRUE))
& i$Val[i$Replicate == "R4"]), ]))
|
Changing Column names of multiple data frames using a for loop with data frames loaded into a List
Tag : r , By : terrestrial
Date : March 29 2020, 07:55 AM
hope this fix your issue I am trying to change the variable names in all data frames in a for loop. Any example of the data is: L <- lapply(L, function(x){
colnames(x) <- c("NewName1", "NewName2")
x
} )
|