Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 根据多个字段和条件将数据规格化为值_R - Fatal编程技术网

R 根据多个字段和条件将数据规格化为值

R 根据多个字段和条件将数据规格化为值,r,R,我对R很陌生。我有一个带有标题(Value,Benchmark,Suite,Var)的表,我想根据(Benchmark,Var)的组合将每个值标准化为基线的平均值。因此,每个条目(值、基准、套件、Var)应标准化为基准的平均值,其中基准和Var相等 数据代表不同的基准测量,其中var是不同的输入大小。数据如下所示: Value Benchmark Suite Var 500 Benchmark2 baseline 1732 889 Benchmark basel

我对R很陌生。我有一个带有标题(Value,Benchmark,Suite,Var)的表,我想根据(Benchmark,Var)的组合将每个值标准化为基线的平均值。因此,每个条目
(值、基准、套件、Var)
应标准化为基准的平均值,其中
基准
Var
相等

数据代表不同的基准测量,其中var是不同的输入大小。数据如下所示:

Value   Benchmark  Suite     Var
500     Benchmark2 baseline  1732
889     Benchmark  baseline  1732
500     Benchmark2 baseline  1732
889     Benchmark  baseline  1732
300     Benchmark  Approach1 1732
100     Benchmark2 Approach1 1732
在转换之后,它将如下所示:

Value   Benchmark  Suite     Var   RuntimeRatio
500     Benchmark2 baseline  1732  1.00
889     Benchmark  baseline  1732  1.00
500     Benchmark2 baseline  1732  1.00
889     Benchmark  baseline  1732  1.00
300     Benchmark  Approach1 1732  0.34 # 300 compared to mean(889,889) of each (Benchmark,baseline,1732)
100     Benchmark2 Approach1 1732  0.20 # 100 compared to mean(500,500) of each (Benchmark2,baseline,1732)
我现在有类似的东西,但这不算正确的东西:

norm <- ddply(data, Var ~ Benchmark, transform,
          RuntimeRatio = Value / mean(Value[Suite == "baseline"]))

norm我认为最好、最干净的方法是在操作之前进行一点数据管理

您的数据:

df <- tibble::tribble(
  
  ~Value, ~Benchmark  ,  ~Suite     , ~Var,
  500   , "Benchmark2", "baseline"  , 1732,
  889   , "Benchmark" , "baseline"  , 1732,
  500   , "Benchmark2", "baseline"  , 1732,
  889   , "Benchmark" , "baseline"  , 1732,
  300   , "Benchmark" , "Approach1" , 1732,
  100   , "Benchmark2", "Approach1" , 1732
  
)
这种方法得到了我认为您可能需要的东西

但是,如果您想要完全符合您的要求,则需要以以下方式将
df_基线
连接到原始
df

df %>% 
  left_join(df_baseline, by = c("Benchmark", "Var")) %>% 
  mutate(RuntimeRatio = Value / Value_baseline) %>% 
  select(-Value_baseline)

# # A tibble: 6 x 5
#   Value Benchmark  Suite       Var RuntimeRatio
#   <dbl> <chr>      <chr>     <dbl>        <dbl>
# 1   500 Benchmark2 baseline   1732        1    
# 2   889 Benchmark  baseline   1732        1    
# 3   500 Benchmark2 baseline   1732        1    
# 4   889 Benchmark  baseline   1732        1    
# 5   300 Benchmark  Approach1  1732        0.337
# 6   100 Benchmark2 Approach1  1732        0.2  
df%>%
左联合(df\U基线,由=c(“基准”,“变量”))%>%
变异(运行时比率=值/值\基线)%>%
选择(-Value\u基线)
##tibble:6 x 5
#价值基准套件Var运行时比率
#                       
#1500基准2基线1732 1
#2889基准基线1732 1
#3500基准2基线1732 1
#4889基准基线1732 1
#5300基准方法1 1732 0.337
#6 100基准2方法1 1732 0.2

我认为最好、最干净的方法是在操作之前进行一点数据管理

您的数据:

df <- tibble::tribble(
  
  ~Value, ~Benchmark  ,  ~Suite     , ~Var,
  500   , "Benchmark2", "baseline"  , 1732,
  889   , "Benchmark" , "baseline"  , 1732,
  500   , "Benchmark2", "baseline"  , 1732,
  889   , "Benchmark" , "baseline"  , 1732,
  300   , "Benchmark" , "Approach1" , 1732,
  100   , "Benchmark2", "Approach1" , 1732
  
)
这种方法得到了我认为您可能需要的东西

但是,如果您想要完全符合您的要求,则需要以以下方式将
df_基线
连接到原始
df

df %>% 
  left_join(df_baseline, by = c("Benchmark", "Var")) %>% 
  mutate(RuntimeRatio = Value / Value_baseline) %>% 
  select(-Value_baseline)

# # A tibble: 6 x 5
#   Value Benchmark  Suite       Var RuntimeRatio
#   <dbl> <chr>      <chr>     <dbl>        <dbl>
# 1   500 Benchmark2 baseline   1732        1    
# 2   889 Benchmark  baseline   1732        1    
# 3   500 Benchmark2 baseline   1732        1    
# 4   889 Benchmark  baseline   1732        1    
# 5   300 Benchmark  Approach1  1732        0.337
# 6   100 Benchmark2 Approach1  1732        0.2  
df%>%
左联合(df\U基线,由=c(“基准”,“变量”))%>%
变异(运行时比率=值/值\基线)%>%
选择(-Value\u基线)
##tibble:6 x 5
#价值基准套件Var运行时比率
#                       
#1500基准2基线1732 1
#2889基准基线1732 1
#3500基准2基线1732 1
#4889基准基线1732 1
#5300基准方法1 1732 0.337
#6 100基准2方法1 1732 0.2

我没有收到你的请求。对于每个三元组基准套件Var,您要计算值/(该三元组的平均值),对吗?我编辑了我的问题。它应该比较数据中的每个条目,并计算其值与基线值的比率,其中
基准
var
是相同的。数据代表不同的基准测量,其中var是不同的输入大小。它们会出现多次,因为基准会重复多次以最小化错误。我没有收到您的请求。对于每个三元组基准套件Var,您要计算值/(该三元组的平均值),对吗?我编辑了我的问题。它应该比较数据中的每个条目,并计算其值与基线值的比率,其中
基准
var
是相同的。数据代表不同的基准测量,其中var是不同的输入大小。它们会出现多次,因为基准会重复多次以最小化错误。