请更改R语言脚本: 要求:groups中每行中若存在0,则每行数据不变,若不存在0,再mid_points <- sapply(groups, function(x) apply(x, 1, median)) new_points <- t(sapply(mid_points, function(x) c(x, x*1.01, x*1.02, x*0.98, x*0.99))) new_points <- round(new_points) 脚本: library(xlsx) data <- read.xlsx("C:/Users/63035/Desktop/shuju/turangweishengwu/taconomy-bac/phylum0302.xlsx",sheetIndex = 1) groups <- split.default(data, rep(1:ncol(data), each=5, length.out=ncol(data))) mid_points <- sapply(groups, function(x) apply(x, 1, median)) new_points <- t(sapply(mid_points, function(x) c(x, x*1.01, x*1.02, x*0.98, x*0.99))) new_points <- round(new_points)
时间: 2023-03-25 10:00:53 浏览: 87
将脚本更改为:如果groups中每行存在,则不进行任何更改;如果不存在,则计算每行的中位数,并将中位数乘以1.01、1.02、.98、.99,生成新的数据点。最后将新的数据点四舍五入。
修改后的脚本如下:
library(xlsx)
data <- read.xlsx("C:/Users/63035/Desktop/shuju/turangweishengwu/taconomy-bac/phylum0302.xlsx",sheetIndex = 1)
groups <- split.default(data, rep(1:ncol(data), each=5, length.out=ncol(data)))
new_points <- t(sapply(groups, function(x) {
if ( %in% x) {
return(x)
} else {
mid_point <- median(x)
c(mid_point, mid_point*1.01, mid_point*1.02, mid_point*.98, mid_point*.99)
}
}))
new_points <- round(new_points)
阅读全文