Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.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
如何创建csv。来自合并例程(R)的表?不知怎的,表格没有保存,我可以';t将其转换为数据帧 你能显示预期的输出吗?输出为data.frame,您可能需要将其分配给对象,即res i canwrite.csv(res,“test.csv”)。没有错_R_Rstudio - Fatal编程技术网

如何创建csv。来自合并例程(R)的表?不知怎的,表格没有保存,我可以';t将其转换为数据帧 你能显示预期的输出吗?输出为data.frame,您可能需要将其分配给对象,即res i canwrite.csv(res,“test.csv”)。没有错

如何创建csv。来自合并例程(R)的表?不知怎的,表格没有保存,我可以';t将其转换为数据帧 你能显示预期的输出吗?输出为data.frame,您可能需要将其分配给对象,即res i canwrite.csv(res,“test.csv”)。没有错,r,rstudio,R,Rstudio,如何创建csv。来自合并例程(R)的表?不知怎的,表格没有保存,我可以';t将其转换为数据帧 你能显示预期的输出吗?输出为data.frame,您可能需要将其分配给对象,即res i canwrite.csv(res,“test.csv”)。没有错误。是的,这就是问题所在,谢谢 library(reshape2) Customer<- c("Susan","Louis", "Frank","Susan") Seller<- c("Ivan", "Donald","Chris"

如何创建csv。来自合并例程(R)的表?不知怎的,表格没有保存,我可以';t将其转换为数据帧
你能显示预期的输出吗?输出为data.frame,您可能需要将其分配给对象,即
res i can
write.csv(res,“test.csv”)
。没有错误。是的,这就是问题所在,谢谢
library(reshape2)
Customer<- c("Susan","Louis", "Frank","Susan")
Seller<- c("Ivan", "Donald","Chris","Ivan")
Service<-c("COU","CAR", "FCL","CAR")
Billingmean<- c(100,200,300,400)
WrsHoldSum<-c(0,0,0,0)
Group<- c("n1","n2"," "," ")
B1<- c(0,2,2,1) 
B2<-c(9,8,7,6)
B3<- c(5,4,3,2)
df<- data.frame(Customer, Seller,Service, Billingmean,WrsHoldSum, Group,B1,B2,B3)
sub1<- dcast(data= df, formula= Customer+Group+Seller+WrsHoldSum~Service,fun.aggregate= sum,value.var= "Billingmean")
sub2<- dcast(data= df, formula= Customer+Group+Seller+WrsHoldSum~Service,fun.aggregate= sum,value.var= "B1") 
sub3<- dcast(data= df, formula= Customer+Group+Seller+WrsHoldSum~Service,fun.aggregate= sum,value.var= "B2")
sub4<- dcast(data= df, formula= Customer+Group+Seller+WrsHoldSum~Service,fun.aggregate= sum,value.var= "B3")
tNames <- grep(x = ls(), pattern = "^sub", value = T)

lapply(seq_along(tNames), function(x){
  tSym <- as.name(tNames[[x]])

  d1 <- copy(eval(tSym))

  cols <- grep(x = names(d1), pattern = "^CAR|^COU|^FCL", value = T)

  setnames(d1, old = cols, new = paste0(cols, " B", x))

  return(d1)

}) %>% Reduce(function(x, y) merge(x, y, by = c("Customer","Group","Seller","WrsHoldSum")), .)
Customer Group Seller WrsHoldSum CAR B1 COU B1 FCL B1 CAR B2 COU B2 FCL B2 CAR B3 COU B3 FCL B3 CAR B4 COU B4 FCL B4
1    Frank        Chris          0      0      0    300      0      0      2      0      0      7      0      0      3
2    Louis    n2 Donald          0    200      0      0      2      0      0      8      0      0      4      0      0
3    Susan         Ivan          0    400      0      0      1      0      0      6      0      0      2      0      0
4    Susan    n1   Ivan          0      0    100      0      0      0      0      0      9      0      0      5      0