Question

I am using the TraMineR package. I am printing output to a CSV file, like this:

write.csv(seqient(sequences.seq), file = "diversity_measures.csv", quote = FALSE, na = "", row.names = TRUE)
write.csv(seqici(sequences.seq), file = "diversity_measures.csv", quote = FALSE, na = "", row.names = TRUE, append= TRUE)
write.csv(seqST(sequences.seq), file = "diversity_measures.csv", quote = FALSE, na = "", row.names = TRUE,  append= TRUE)

The dput(sequences.seq) object can be found here.

However, this does not append the output properly but creates this error message:

In write.csv(seqST(sequences.seq), file = "diversity_measures.csv",  :attempt to set 'append' ignored

Additionally, it only gives me the output for the last command, so it seems like it overwrites the file each time.

Is it possible to get all the columns in a single CSV file, with a column name for each (i.e. entropy, complexity, turbulence)

Was it helpful?

Solution

You can use append=TRUE in write.table calls and use the same file name, but you'll need to specify all the other arguments as needed. append=TRUE is not available for the wrapper function write.csv, as noted in the documentation:

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.

Or you could write out

write.csv(data.frame(entropy=seqient(sequences.seq), 
                     complexity=seqici(sequences.seq), 
                     turbulence=seqST(sequences.seq)),
          'output.csv')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top