首页 > 解决方案 > 如何将 R 图附加到 csv 文件中的给定列?

问题描述

我知道如何使用 R 将“说数字”附加到 csv 文件。我想要的是将相应的图表也粘贴到相应列中的同一文件中。这是我尝试过的代码,但失败了。请帮忙。

library(muhaz)
library(readr)

ball_data <- read_csv("C:/Users/dovini jayasinghe/Desktop/Cricket/ball data.csv")

attach(ball_data)
#View(ball_data)

for(i in 1:3){
  fit <- muhaz(times = scoreValue[help_index2==i], 
               delta = Censored[help_index2==i], 
               bw.method="local", 
               kern="epanechnikov", 
               max.time=max(scoreValue[help_index2==i]))
  
  graph <- plot(fit)#draws the plot
  
  max_x <- max(fit$pin$times)
  
  #data frame excluding the graph
  df <- data.frame("Ball Number" = i,
                   "Maximum Score" = max_x
                   )
  
  #if we need the graph, I think the code is this way
  # df <- data.frame("Ball Number" = i,
  #                  "Maximum Score" = max_x,
  #                  "Graph" = graph)
  
  
  write.table(df,
              'C://Users//dovini jayasinghe//Desktop//Cricket//hazard_i_th_ball.csv',
              row.names = FALSE,
              col.names = FALSE,
              sep = ",",
              append = TRUE)
}

具体来说,我需要一个像这样的表(一个csv文件)

球号 最高分 图形
1 4 图 1 的图像
2 1 图 2 的图像
3 3 图 3 的图像

标签: rdataframeplotappendexport-to-csv

解决方案


推荐阅读