我想通过一个特定列中的值对数据进行标准化。换句话说,我想将每一行中的所有值除以特定列中的值。
例如:
数据文件是
Gene P1 P2 P3
A1 6 8 2
A2 12 6 3
A3 8 4 8 我希望将每行中的所有值除以列P3的该行中的值。
Gene P1 P2 P3
A1 6/2 8/2 2/2
A2 12/3 6/3 3/3
A3 8/8 4/8 8/8 新的数据将是:
Gene P1 P2 P3
A1 3 4 1
A2 4 2 1
A3 1 .5 1谢谢你的帮助。
发布于 2021-06-15 01:22:54
使用tidyverse函数:
library(tidyverse)
df1 <- read.table(text = "Gene P1 P2 P3
A1 6 8 2
A2 12 6 3
A3 8 4 8", header = TRUE)
df1 %>%
mutate(across(.cols = -c(Gene), .fns = ~ .x / P3))
# Gene P1 P2 P3
#1 A1 3 4.0 1
#2 A2 4 2.0 1
#3 A3 1 0.5 1发布于 2021-06-15 07:03:59
你可以直接划分列-
cols <- 2:3
df[cols] <- df[cols]/df$P3
df
# Gene P1 P2 P3
#1 A1 3 4.0 2
#2 A2 4 2.0 3
#3 A3 1 0.5 8https://stackoverflow.com/questions/67978819
复制相似问题