Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the following R script:

target <- c("Autocorrelation","InformationContent_zero","InformationContent_one","InformationContent_two",
            "InformationContent_four","PartialIC_zero","PartialIC_one","PartialIC_two","PartialIC_four",
            "DBI_zero","DBI_one","DBI_two","DBI_four")

for (tar in target){
  AC_data <- subset(data, select=c(tar))
  AC <- aggregate(AC_data , list(class=data$TARGET_CLASS), mean)
  ordered_AC <- AC[order(-AC[tar]),]
  write.csv(ordered_AC,file="/home/nasser/Desktop/Experiments/evosuite-report/finalData.csv",append=TRUE)
}

When I run the script with the data that I process I get the following results:

                    class Autocorrelation
16    SomeExternalClass11      0.26582445
3     MoreMethodsModified      0.21295785
10  MultiPlateauxModified      0.19942221
1             DoublePeaks      0.19534564
                    class InformationContent_zero
2             MoreMethods              0.17936452
7              MultiPeaks              0.13527150
12 NeedleInHaystackNoParm              0.11714634
6    MultiMethodsModified              0.07180512
                    class InformationContent_one
2             MoreMethods             0.17936452
7              MultiPeaks             0.13527150
12 NeedleInHaystackNoParm             0.11714634
6    MultiMethodsModified             0.07180512

The problem is that the only data that is written to the CSV file is the last group which is class InformationContent_one

That means the first two groups are overwritten. Do you know how to fix this and let all the data are written to the CSV file?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
406 views
Welcome To Ask or Share your Answers For Others

1 Answer

In the help for write.table, it states:

write.csv and write.csv2 provide convenience wrappers for writing CSV files.

...

These wrappers are deliberately inflexible: they are designed to ensure that the correct conventions are used to write a valid file. Attempts to change append, col.names, sep, dec or qmethod are ignored, with a warning.

If you want to append, you need to use write.table explicitly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...