通过基于R中不断变化的数据集的比率使用归一化数据 [英] Normalize data by use of ratios based on a changing dataset in R

查看:104
本文介绍了通过基于R中不断变化的数据集的比率使用归一化数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过将所有值转换为百分比来标准化Y比例尺. 因此,我需要将一列中的每个数字除以该列中的第一个数字.在Excel中,这等效于锁定单元格A1/$ A1,B1/$ A1,C1/$ A1,然后锁定D1/$ D1,E1/$ D1 ...

I am trying to normalize a Y scale by converting all values to percentages. Therefore, I need to divide every number in a column by the first number in that column. In Excel, this would be equivalent to locking a cell A1/$A1, B1/$A1, C1/$A1 then D1/$D1, E1/$D1...

数据首先需要满足四个标准(时间,处理,浓度和类型),并且每次新处理时参考值都会发生变化.每种处理均具有4种浓度(0、0.1、2和50).我希望将与每个浓度关联的值除以参考值(当浓度等于0时).

The data needs to first meet four criteria (Time, Treatment, Concentration and Type) and the reference value changes at every new treatment. Each treatment has 4 concentrations (0, 0.1, 2 and 50). I would like for the values associated to each concentration to be divided by the reference value (when the concentration is equal to 0).

棘手的部分是该参考值每4行更改一次.

The tricky part is that this reference value changes every 4 rows.

我尝试使用ddply进行此操作:

I have tried doing this using ddply:

`MasterTable <- read.csv("~/Dropbox/Master-table.csv")`
  MasterTable <- ddply(MasterTable, .(Time, Type, Treatment), transform, pc=(Value/Value$Concentration==0)) 

但这根本不起作用.任何帮助将不胜感激!

But this is not working at all. Any help would be really appreciated!

我的数据文件可以在这里找到: 主表

My data file can be found here: Master-table

谢谢!

推荐答案

dplyr在这里非常有效:

library(dplyr)
result <- group_by(MasterTable, Time, Type, Treatment) %>%
  mutate(pc = Value / Value[1])

这篇关于通过基于R中不断变化的数据集的比率使用归一化数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆