将data.frame中的所有列乘以第一个 [英] multiply all the columns in a data.frame by the first
本文介绍了将data.frame中的所有列乘以第一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将 data.frame
中的每一列乘以第一列(类因子)中的值。
I need to multiply each column in a data.frame
by the values in first column (classfactor).
这是我的 data.frame
sample classfactor 01.BA.V 01.BA.VG 01.BO.VG 01.PR.O 01.TO.VG 02.BA.O 02.BA.V
AB 0.730 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0 0.00000000
AC 0.730 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0 0.00000000
AB 0.002 0.000000000 0.000000000 0.000749929 0.000000000 0.000000000 0 0.00000000
CC 0.730 0.081599145 0.093453018 0.031247022 0.015987076 0.036212483 0 0.02537884
BB 0.730 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0 0.00000000
AA 0.730 0.001533075 0.000108666 0.000000000 0.000364526 0.000241417 0 0.00006340
它有146行和155列。
It has 146 rows and 155 columns.
我不知道该怎么做。有建议吗?
I can't figure out how to do. Any suggestions?
推荐答案
如果我没记错的话,你可以做
If I'm not mistaken, you can do
df[-(1:2)] <- df[["classfactor"]] * df[-(1:2)]
其中 df
是您的数据框,第一列是样本
( classfactor
实际上是第二列)。
where df
is your data frame and the first column is sample
(classfactor
is actually the second column).
这篇关于将data.frame中的所有列乘以第一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文