DF有4列,前3列乘以12

时间:2013-06-24 12:00:32

标签: r dataframe multiplication

我有一个数据框,其中包含3列数值(p值)和1列频率值(不应该相乘)。我想将前3列相乘,让最后一列不变。

my.df:

myfamDF<-structure(list(MASHvstRap = c(3.36388469632471e-14, 4.33277656523673e-123, 
3.06769943976602e-08, 6.07022175358029e-30, 4.82890837154273e-32, 
4.93181852868703e-06, 1.22573775496788e-08, 1.25502843779857e-05, 
1.72864219357795e-05, 4.71138538453502e-05, 8.34818462488622e-05, 
1.62205005760679e-17), MASHvsBEEML = c(0.763756578209722, 0.442020719677047, 
0.423594358667165, 0.0994358268075855, 0.0736357072352032, 0.0467257430288347, 
0.00119919900578073, 0.00094114146973297, 0.000840376826415137, 
0.000623286035357452, 0.000250015234002341, 1.46483433509648e-08
), tRapvsBEEML = c(3.75944533892572e-07, 8.44025048683083e-74, 
7.51004008659922e-09, 5.3728011843321e-09, 7.20783906680568e-26, 
6.69189512726035e-07, 3.60117573203279e-07, 1.17030570144044e-06, 
2.54589884424594e-07, 3.93333369828925e-07, 8.80480124829088e-06, 
2.89656372293867e-25), frequency = c(19, 158, 11, 44, 121, 10, 
13, 10, 10, 17, 10, 54)), .Names = c("MASHvstRap", "MASHvsBEEML", 
"tRapvsBEEML", "frequency"), row.names = c("Homeo ", "Homeo", 
"Homeo, POU", "HMG", "unknown", "ZnF_C4", "HLH", "IRF", "FH", 
"Zn2Cys6", "ETS", "ZnF_C2H2"), class = "data.frame")

我尝试了以下内容: myfamDF[1:3] * 12 但这只给了我前3列,第4列失败了。如何维护所有列并将前3个乘以12。

2 个答案:

答案 0 :(得分:5)

你几乎拥有它:

myfamDF[, 1:3] <- myfamDF[, 1:3] * 12

答案 1 :(得分:4)

transform(myfamDF, MASHvstRap=MASHvstRap*12, MASHvsBEEML=MASHvsBEEML*12, tRapvsBEEML=tRapvsBEEML*12)
## or ##
cbind(myfamDF[,1:3]*12, myfamDF[,4])