根据R中另一列的特定值计算多列的均值

问题描述 投票:0回答:0

使用以下数据

##### install.packages("letsR") ######
library(letsR)
data("PAM")

###### get any rasters layers for example #####
wcpath <- list.files(system.file("extdata/bios",
                                package = "ntbox"),
                    pattern = ".tif$",full.names = TRUE)

r <- raster::stack(wcpath) #####

##### Add the raster values to a presence absence matrix ######
projection(PAM$Richness_Raster) <- projection(r)

##### The object PAM_env, is a presence absence matrix with columns Longitude, Latitude,species are ##### in every column and then the final columns are environmental layers
PAM_env <- lets.addvar(PAM, r, fun = mean)

我想计算每个物种(第 3 至 34 列)的每个气候层(第 35 至 53 列)的平均值,但仅考虑每个物种的行等于 1 的情况)

我想在循环中计算什么

获取

Species Var_1_mean_run_1, Var_2_mean_run_1, Var_1_mean_run_2, Var_2_mean_run_2, etc

Every run contains the same species with their geographic range shifted,所以我需要重新计算每个物种的这个属性值(它们在分布范围内的平均温度)

谢谢你的时间,

凯文

我想计算每个物种(第 3 至 34 列)的每个气候层(第 35 至 53 列)的平均值,但仅考虑每个物种的行等于 1 的情况)

r dataframe loops multiple-columns bioinformatics
© www.soinside.com 2019 - 2024. All rights reserved.