无法强制类....对data.frame错误

时间:2013-06-20 05:32:00

标签: r

R主题

尝试将摘要保存在文件中时,我有一个“无法强制类”c(“summary.turnpoints”,“turnpoints”)“to data.frame”错误。我试图用as.data.frame修复它,但没有成功。

代码:

library(plyr)
library(pastecs)

 data <- read.table("C:\\Users\\Ron\\Desktop\\dataset.txt", header=F, col.name="A")
 data.tp=turnpoints(data$A)
 print(data.tp)

转折点:数据$ A

nbr observations  : 5990 
nbr ex-aequos     : 51 
nbr turning points: 413 (first point is a pit)
E(p) = 3992 Var(p) = 1064.567 (theoretical)

转折点:数据$ A

nbr observations  : 5990 
nbr ex-aequos     : 51 
nbr turning points: 413 (first point is a pit)
E(p) = 3992 Var(p) = 1064.567 (theoretical)


 data.sum=summary(data.tp)
 print(data.sum)

    point type        proba      info
1      11  pit 7.232437e-15  46.97444
2      21 peak 7.594058e-14  43.58212
3      30  pit 3.479857e-27  87.89303
4      51 peak 5.200612e-29  93.95723
5      62  pit 7.594058e-14  43.58212
6      70 peak 6.213321e-14  43.87163
7      81  pit 6.276081e-16  50.50099
8      91 peak 5.534016e-23  73.93602
.....................................

write.table(data.sum, file = "C:\\Users\\Ron\\Desktop\\datasetTurnP.txt")

Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : 
  cannot coerce class "c("summary.turnpoints", "turnpoints")" to a data.frame
In addition: Warning messages:
1: package ‘plyr’ was built under R version 3.0.1 
2: package ‘pastecs’ was built under R version 3.0.1 

如何将这些摘要结果保存到文本文件?

谢谢。

1 个答案:

答案 0 :(得分:3)

查看以下的值部分:

?pastecs::summary.turnpoints

应该清楚的是,这不是一组列表,所有列表都具有相同的长度。因此错误消息。所以,而不是要求不可能,...告诉我们你想要保存什么。

实际上并非不可能,只有write.table无法实现,因为它不是数据帧。 dump函数允许您构造该摘要对象的structure(...)表示的ASCII表示。

dump(data.sum, file="dump_data_sum.asc")

这可能是source()-ed