Use dump or write? or what?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Use dump or write? or what?

oaxacamatt
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: [hidden email]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Use dump or write? or what?

Dieter Menne
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
Reply | Threaded
Open this post in threaded view
|

Re: Use dump or write? or what?

Jeffrey Dick
In reply to this post by oaxacamatt
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 <[hidden email]> 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: [hidden email]
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Use dump or write? or what?

jholtman
In reply to this post by oaxacamatt
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 <[hidden email]> 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: [hidden email]
>
> ______________________________________________
> [hidden email] 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?

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Use dump or write? or what?

oaxacamatt
In reply to this post by oaxacamatt
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 <[hidden email]> 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: [hidden email]
>



--


Matt Curcio
M: 401-316-5358
E: [hidden email]

______________________________________________
[hidden email] 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.