Greetings all, I am calculating two t-test values for each of many files then save it to file calculate another set and append, repeat. But I can't figure out how to write it to file and then append subsequent t-tests. (maybe too tired ;} ) I have tried to use "dump" and "file.append" to no avial. ttest_results = tempfile() two_sample_ttest <- t.test (tempA, tempB, var.equal = TRUE) welch_ttest <- t.test (tempA, tempB, var.equal = FALSE) dump (two_sample_ttest, file = "dumpdata.txt"", append=TRUE) ttest_results <- file.append (ttest_results, two_sample_ttest) Any suggestions, M -- Matt Curcio M: 401-316-5358 E: matt.curcio.ri at gmail.com
oaxacamatt wrote:> > I am calculating two t-test values for each of many files then save it > to file calculate another set and append, repeat. >You did not tell use what you want to do with the data in the file. If you just want a copy of the output, bracketing with sink(file) and sink() can be useful. If you want to process the results later, try save/load. Dieter -- View this message in context: http://r.789695.n4.nabble.com/Use-dump-or-write-or-what-tp3708904p3709031.html Sent from the R help mailing list archive at Nabble.com.
Hi Matt, I assume that you want a tabular text file of the results. Since I don't know what your tempA and tempB are I'll steal some examples from ?t.test> t.example.1 <- t.test(1:10,y=c(7:20)) > t.example.2 <- t.test(1:10,y=c(7:20, 200))Now looking at ?dump, the first argument needs to be *character*, signifying "The names of one or more R objects to be dumped." So put the names of the objects in quotes. I'm ignoring your "ttest_results tempfile()" line because it appears you want to put the results into "dumpdata.txt".> dump ("t.example.1", file = "dumpdata.txt") > dump ("t.example.2", file = "dumpdata.txt", append=TRUE)Both objects show up in the file (yay!) but the result probably isn't what you're after, with some R-like code along the lines of t.example.1 <- structure(list(statistic [ ... lots of other stuff that isn't in a tabular format ... ] write()ing a list isn't the way to go either:> write(t.example.1,"test.txt")Error in cat(list(...), file, sep, fill, labels, append) : argument 1 (type 'list') cannot be handled by 'cat' write.table() of the whole result gives some kind of problem as well:> write.table(t.example.1,"test.txt")Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : cannot coerce class '"htest"' into a data.frame What about saving only part of the results? The first line below overwrites the "dumpdata.txt" created above. The second line appends to the file, and also doesn't write the column names because they are already present from the first write.table.> write.table(t.example.1[1:3], "dumpdata.txt") > write.table(t.example.2[1:3], "dumpdata.txt", append=TRUE, col.names=FALSE)There are certainly many variations to try. This writes only the "statistic", "parameter" and "p.value" of the t-tests. Here is the resulting file.> cat(readLines("dumpdata.txt"), sep="\n")"statistic" "parameter" "p.value" "t" -5.43492976389406 21.982212340189 1.85528183251181e-05 "t" -1.63290263320121 14.1645989530125 0.124513498089745 Jeff On Sun, Jul 31, 2011 at 8:41 PM, Matt Curcio <matt.curcio.ri at gmail.com> wrote:> Greetings all, > I am calculating two t-test values for each of many files then save it > to file calculate another set and append, repeat. > But I can't figure out how to write it to file and then append > subsequent t-tests. > (maybe too tired ;} ) > I have tried to use "dump" and "file.append" to no avial. > > ttest_results = tempfile() > > two_sample_ttest <- t.test (tempA, tempB, var.equal = TRUE) > welch_ttest <- t.test (tempA, tempB, var.equal = FALSE) > > dump (two_sample_ttest, file = "dumpdata.txt"", append=TRUE) > ttest_results <- file.append (ttest_results, two_sample_ttest) > > Any suggestions, > M > -- > > > > Matt Curcio > M: 401-316-5358 > E: matt.curcio.ri at gmail.com > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Can you define better exactly what you what to do with the data. I would suggest that you keep each of the outputs (objects) of the test in a 'list' that way you can access each one and do what you need. You can also 'save' the list and later 'load' it into another session. On Sun, Jul 31, 2011 at 11:41 PM, Matt Curcio <matt.curcio.ri at gmail.com> wrote:> Greetings all, > I am calculating two t-test values for each of many files then save it > to file calculate another set and append, repeat. > But I can't figure out how to write it to file and then append > subsequent t-tests. > (maybe too tired ;} ) > I have tried to use "dump" and "file.append" to no avial. > > ttest_results = tempfile() > > two_sample_ttest <- t.test (tempA, tempB, var.equal = TRUE) > welch_ttest <- t.test (tempA, tempB, var.equal = FALSE) > > dump (two_sample_ttest, file = "dumpdata.txt"", append=TRUE) > ttest_results <- file.append (ttest_results, two_sample_ttest) > > Any suggestions, > M > -- > > > > Matt Curcio > M: 401-316-5358 > E: matt.curcio.ri at gmail.com > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve?
Greetings all, Thanks for all your help so far. Let me give a better idea of what I am doing. I have hundreds of files that I need to plow thru with a t-test and correlation test. BTW, 'tempA' and tempB' are simply columns of numbers from a gene-chip experiment that spits out dna 'amounts'. So I have set up a loop to read the files and carry out the tests but need to save it for later inspection (and Jim H-you are probably right, for later inspection). By inspection I mean I don't know what I want to do with it yet, Remember: "That's why they call it Research." So it seems that 'save/load' might be a good alternative for my work. Any suggestions, M On Sun, Jul 31, 2011 at 11:41 PM, Matt Curcio <matt.curcio.ri at gmail.com> wrote:> Greetings all, > I am calculating two t-test values for each of many files then save it > to file calculate another set and append, repeat. > But I can't figure out how to write it to file and then append > subsequent t-tests. > (maybe too tired ;} ) > I have tried to use "dump" and "file.append" to no avial. > > ttest_results = tempfile() > > two_sample_ttest <- t.test (tempA, tempB, var.equal = TRUE) > welch_ttest <- t.test (tempA, tempB, var.equal = FALSE) > > dump (two_sample_ttest, file = "dumpdata.txt"", append=TRUE) > ttest_results <- file.append (ttest_results, two_sample_ttest) > > Any suggestions, > M > -- > > > > Matt Curcio > M: 401-316-5358 > E: matt.curcio.ri at gmail.com >-- Matt Curcio M: 401-316-5358 E: matt.curcio.ri at gmail.com