我无法在线找到此问题的解决方案,就像看起来那么简单。下面是它是: 我有这样名称的数据帧DF1:用矩阵代替data.frame
PIM WDR MYC OBX
ILMN_1651282 0.555764 0.675233 0.5908629 0.4897703
ILMN_1651354 0.6963458 0.8588675 0.9216328 0.88705
ILMN_1651358 0.7501548 0.6766059 0.8157319 0.9373666
ILMN_1652716 0.5505098 0.5802357 0.7342341 0.5953167
ILMN_1654324 0.9294231 0.9311051 0.8424824 0.888825
ILMN_1654639 0.9197155 0.4687101 0.678938 0.4309232
ILMN_1655418 0.690068 0.6345875 0.9595042 0.6132203
像这样名称的dataframefile DF2:
PIM WDR MYC OBX
ILMN_1651282 -1 -1 -1 -1
ILMN_1651354 -1 1 1 1
ILMN_1651358 1 1 1 1
ILMN_1652716 -1 -1 -1 -1
ILMN_1654324 -1 -1 -1 -1
ILMN_1654639 -1 -1 -1 -1
ILMN_1655418 1 1 -1 1
我有0.8的临界值。在DF1高于0.8的每一个值在0改变所有0.8下的值必须由值DF2被替换(1 & -1)
创建DF2:
PIMvsEV<-list()
for (x in 1:nrow(df1)) {
t<-(if (mean(PIM[,x]) > mean(EV[,x])) {print(1)} else
if (mean(PIM[,x]) < mean(EV[,x])) {print(-1)})
PIMvsEV[[x]]<-matrix(t)
}
WDRvsEV<-list()
for (x in 1:nrow(df1)) {
t<-(if (mean(WDR[,x]) > mean(EV[,x])) {print(1)} else
if (mean(WDR[,x]) < mean(EV[,x])) {print(-1)})
WDRvsEV[[x]]<-matrix(t)
}
OBXvsEV<-list()
for (x in 1:nrow(cdf1)) {
t<-(if (mean(OBX[,x]) > mean(EV[,x])) {print(1)} else
if (mean(OBX[,x]) < mean(EV[,x])) {print(-1)})
OBXvsEV[[x]]<-matrix(t)
}
MYCvsEV<-list()
for (x in 1:nrow(df1)) {
t<-(if (mean(MYC[,x]) > mean(EV[,x])) {print(1)} else
if (mean(MYC[,x]) < mean(EV[,x])) {print(-1)})
MYCvsEV[[x]]<-matrix(t)
}
dataframe<-as.data.frame(cbind(as.matrix(PIMvsEV), as.matrix(WDRvsEV)))
dataframe<-as.data.frame(cbind(as.matrix(dataframe), as.matrix(MYCvsEV)))
dataframe<-as.data.frame(cbind(as.matrix(dataframe), as.matrix(OBXvsEV)))
row.names(dataframe)<-colnames(ttest)
colnames(dataframe)<-c("PIM","WDR","MYC","OBX")
任何想法?事先非常感谢,
Lisanne
您是否试过使用应用函数? http://nsaunders.wordpress.com/2010/08/20/a-brief-introduction-to-apply-in-r/ – 2011-03-11 09:47:19
只是一个快速的Q,你是如何派生df2的? – 2011-03-11 11:29:25
我是否有权假定您的df1中的数据具有与列一样多的行数?什么是电动汽车? – 2011-03-11 12:06:17