0

I want to export fake.bc.Rdata in package "qtl" into a CSV, and when running "summary" it shows this is an object of class "cross", which makes me fail to convert it. And I tried to use resave, but there is warning :cannot coerce class ‘c("bc", "cross")’ to a data.frame.

Thank you all for your help in advance!

KaiLi
  • 46
  • 4
  • Not all data can be stored in a CSV file. The data needs to have clear columns and rows. What exactly do you want this CSV file to look like? – MrFlick Jul 04 '20 at 18:39
  • I want CSV showing clearly how the example data arrange, and then I know how deal with my personal data. Do you think it is possible to export 2 or more CSVs? – KaiLi Jul 04 '20 at 18:49
  • When you use str([your data frame name here]) what does it show? – Michelle Jul 04 '20 at 19:56
  • like that: str(fake.bc) List of 2 $ geno :List of 19 $ pheno:'data.frame': 400 obs. of 4 variables: – KaiLi Jul 05 '20 at 07:31

1 Answers1

0

CSV stands for comma-separated values, and is not suitable for all kinds of data. It requires, like indicated in the comments, clear columns and rows.

Take this JSON as an example:

{ 
"name":"John",
 "age":30,
 "likes":"Walking","Running"
}

If you were to represent this in CSV-format, how would you deal with the difference in length? One way would be to have repeated data

name,age,likes
John,30,Walking
John,30,Running

But that doesn't really look right. Even if you merge the two into one you would still have trouble reading the data back, e.g.

name,age,likes
John,30,Walking/Running

Thus, CSV is best suited for tidy data.

TL;DR

Can your data be represented tidily as comma-separated values, or should you be looking at alternative forms of exporting your data?

EDIT:

It appears you do have some options: If you look at the reference, you have the option to export your data using write.cross().

For your data, you could use write.cross(fake.bc, "csv", "myCrossData", c(1,5,13)). It then does the following:

Comma-delimited formats: a single csv file is created in the formats "csv" or "csvr". Two files are created (one for the genotype data and one for the phenotype data) for the formats "csvs" and "csvsr"; if filestem="file", the two files will be names "file_gen.csv" and "file_phe.csv".

mhovd
  • 3,724
  • 2
  • 21
  • 47