【发布时间】:2015-10-12 12:40:05
【问题描述】:
我有 2 个数据帧
> head(cont)
old_pert cmap_name conc perturb_geo t1 t2 t3 t4 t5
1 5202764005789148112904.A02 estradiol 0.00000001 GSM119257 GSM119218 GSM119219 GSM119221 GSM119222 GSM119223
2 5202764005789148112904.A01 valproic acid 0.00050000 GSM119256 GSM119218 GSM119219 GSM119221 GSM119222 GSM119223
> head(expression)[1:3,1:8]
GSM118911 GSM118912 GSM118913 GSM118723 GSM118724 GSM118725 GSM118726 GSM118727
1007_s_at 387.6 393.2 290.5 378.6 507.8 383.7 288.8 451.9
1053_at 56.4 53.5 32.8 39.0 71.5 47.3 46.0 50.1
117_at 6.3 33.6 19.2 17.6 20.3 15.0 7.1 43.1
我想应用一个循环来做:
for(i in 1:nrow(cont)){
首先从cont 中取一些值,这些值将在前面使用
vehicle <- cont[i, 5:9]
perturb <- cont[i, 4]
col_name <- paste(cont[i, 2], cont[i, 3], sep = '_') #estradiol_.00001
tmp <- sum(expression[,which(colnames(expression) == vehicle)])/5
tmp2 <- expression[,which(colnames(expression) == perturb)]
tmp3 <- tmp/tmp2
div <- cbind(div, tmp3)
colnames(div)[i + 1] <- col_name
}
从expression 那里获取col.names == vehicle & perturb 中的那些列并应用除法。
div <- expression$vehicle / expression$perturb #I'm not getting how I can pass here the value in `vehicle` and `perturb`
为这个新变量分配一个列名,该列名应该是drug_name 和concentration 的组合
col.names(div) <- drug_name_concentration
为其分配表达式的row.names:
row.names(div) <- row.names(expression)
所以这个过程将迭代 271 次 (nrow(cont) = 271) 并且每次新的分割列将 cbind 到我之前的 div。因此最终结果将是:
arachidonic acid_0.000010 oligomycin_0.000001 .........
1007_s_at 0.45 0.30
1053_at 1.34 0.65
117_at 0.11 0.67
.....
.....
我的头脑中的逻辑很清楚,但我不知道该怎么做。感谢您的帮助。
【问题讨论】: