gpt4 book ai didi

r - 无法强制类 .... 到 data.frame 错误

转载 作者:行者123 更新时间:2023-12-01 09:07:32 28 4
gpt4 key购买 nike

R主题

尝试将摘要保存在文件中时,我有一个“无法将类“c(“summary.turnpoints”,“turnpoints”)”强制转换为 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)

转折点:data$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$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

如何将这些汇总结果保存到文本文件中?

谢谢你。

最佳答案

查看以下的值(value)部分:

?pastecs::summary.turnpoints

应该清楚的是,这不会是一组长度都相同的列表。因此出现错误消息。因此,与其要求不可能的事情,不如告诉我们您想保存什么。

这实际上并非不可能,只是 write.table 不可能,因为它不是数据框。 dump函数将允许您构造 structure(...) 的 ASCII 表示该摘要对象的表示。
dump(data.sum, file="dump_data_sum.asc")

这可能是 source()-ed

关于r - 无法强制类 .... 到 data.frame 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17205971/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com