[R] t.test in for loop

David Winsemius dwinsemius at comcast.net
Thu Jul 22 19:35:28 CEST 2010


On Jul 22, 2010, at 1:28 PM, Arne Schulz wrote:

> Dear list,
> I'd like to do several t-test within a for loop. Example follows:
>
> data1 <- rnorm(1:25)
> data2 <- rnorm(1:25)
> vars <- c("data1", "data2")
>
> for (i in vars) {
> 	t.test(i)	
> }
>
> Unfortunately, it does not work because of the quotes in the vars- 
> vector (running t.test(data1) by hand works).
>
> How can I remove the quotes before performing the test?

a) don't quote them
b) put them in a list
c) print() the results.

-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list