3
votes

R subject

I have an "cannot coerce class "c("summary.turnpoints", "turnpoints")" to a data.frame" error when trying to save the summary in a file. I have tried to fix that with as.data.frame with no success.

code :

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)

Turning points for: 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)

Turning points for: 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 

How can I save these summary results to a text file?

Thank you.

1

1 Answers

3
votes

Look at the Value section of:

?pastecs::summary.turnpoints

It should be clear that this will not be a set of lists all of which have the same length. Hence the error message. So rather than asking for the impossible, ... tell us what you wanted to save.

It's actually not impossible, just not possible with write.table, since it's not a dataframe. The dump function would allow you to construct an ASCII representation of the structure(...) representation of that summary-object.

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

This could then be source()-ed