[R] Saving results of Kruskal Walis test

Bernardo Rangel Tura tura at centroin.com.br
Fri Oct 17 05:01:14 CEST 2008


Em Qui, 2008-10-16 às 22:31 +0200, Himanshu Ardawatia escreveu:
> Hello,
> 
> I am running Kruskal-Walis test in R. When I try to save results using
> write.table it gives me the following error :
> 
> Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors =
> stringsAsFactors) :
>   cannot coerce class "htest" into a data.frame
> 
> The overall code is as follows :
> 
> >data_file = read.table("~/DATA.dir/data_file.txt", header=T)
> 
> >attach(data_file)
> 
> >data_file.out <- krukal.test(data_file)
> 
> >write.table(data_file.out, "~/DATA/results/data_file_out.txt")
> 
> Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors =
> stringsAsFactors) :
>   cannot coerce class "htest" into a data.frame
> Results do come in data_file.out after analysis as seen below:
> 
> >data_file.out
> 
> 
>     Kruskal-Wallis rank sum test
> 
> data:  value by pathway
> Kruskal-Wallis chi-squared = 5.6031, df = 3, p-value = 0.1326
> 
> 
> I am wondering if I am making a mistake with using write.table (It works
> very well saving results from anova analysis) or is there any other way to
> save results in a file for future use..
> 
> Thanks
> Himanshu


Hi Himanshu 

Well the output of htests is a list so data_file.out is a lista to.

You don't put a list ins a data.frame so you need make this


data.frame(unlist(data_file.out))

-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil



More information about the R-help mailing list