If you really want a .csv file then you could create an empty .csv file
using the `file` function then use `cat` or `write.csv` (or other
functions) to write a line to that file each itteration.

Or you could create a matrix of the correct dimensions and just insert a
value into the matrix at each itteration.


On Fri, Apr 19, 2013 at 9:58 AM, Kerstin Kober <Kerstin.Kober@jncc.gov.uk>wrote:

>  ** **
>
> ** **
>
> Hello everybody,****
>
> ** **
>
> I've got some code which runs wilcoxon tests for each 'year' and
> 'hotspot_ID' combination from my data. It basically compares the densities
> each hotspot_Id with the densities in hotspot 0 (one of the hotspot_ID's
> which means 'everywhere else that is not in a hotspot') – some test data is
> attached. ****
>
> ** **
>
> It looks like this. It gives me a nice, and very big, word document with
> all the tests in there. ****
>
> ** **
>
> d<-read.csv("F:\\Offshore_analysis1_(UK_wide_approach)
> \\Extra_analyses\\test_regularity_without_nim_numbers\\3_data_for_R\\6360_wn.csv",
> header=T)****
>
>  ****
>
> # all tests between 0 and the other groups within each year together****
>
> for(i in 1980:2005){****
>
>     for(j in 1:34){****
>
>         tmp<- d[d$YEAR == i & d$hotspot_ID %in% c(0, j), ]****
>
>         print(c(i, j))****
>
>         try(print(wilcox.test(DENSITY~factor(hotspot_ID), data= tmp,
> na.action = na.omit)))****
>
>     }****
>
> }****
>
>  ****
>
> ** **
>
> Note that many of these did not run as there is not data for every
> combination of year and hotspot. ****
>
> ** **
>
> I want to be able to quickly extract which combinations ran, and of those,
> which had a P value less than some threshold, lets say 0.05. ****
>
> ** **
>
> So I'd like to extract some kind of table or ideally a .csv file with 3
> columns:****
>
> Year, Hotspot_ID, P-value. ****
>
> ** **
>
> My attempts at altering the code to do that are here.****
>
> ** **
>
> d<-read.csv("F:\\offshore_SPAs\\1_Stage1\\2_analysis_GL1.4\\2_UK_wide\\3_data_for_R.\\220_br.csv",
> header=T)****
>
>  ****
>
> # all tests between 0 and the other groups within each year together****
>
>   output.2<-matrix( ncol=3, nrow=3000)****
>
>  ****
>
> for(i in 1980:2005){****
>
>     for(j in 1:34){****
>
>         tmp<- d[d$YEAR == i & d$hotspot_ID %in% c(0, j), ]****
>
>         print(c(i, j))****
>
>         try(wt<-(wilcox.test(DENSITY~factor(hotspot_ID), data= tmp,
> na.action = na.omit)****
>
>         )****
>
>         output.2$p<-wt$p.value)****
>
>       }****
>
> }****
>
>       ****
>
> ** **
>
> ** **
>
> I've played around quite a bit with the placement of the output bits, ****
>
> I'm hoping someone can spot either where I'm going wrong with my attempts,
> or suggest a better way of doing this. I've also played a bit with matrix,
> and less so with sapply, but don't really know what I'm doing with those.
> ****
>
> ** **
>
> Any advice greatly appreciated. ****
>
> ** **
>
> Thanks****
>
> ** **
>
> ** **
>
> Kerstin****
>
> ** **
>
> ** **
>
> _____________________________________________________________________
> The Joint Nature Conservation Committee (JNCC) is the statutory adviser to
> Government on UK and international nature conservation, on behalf of the
> Council for Nature Conservation and the Countryside, Cyfoeth Naturiol Cymru
> (Natural Resources Wales), Natural England and Scottish Natural Heritage.
> Its work contributes to maintaining and enriching biological diversity,
> conserving geological features and sustaining natural systems.
>
> JNCC SUPPORT CO. Registered in England and Wales, company no. 05380206.
> Registered office: Monkstone House, City Road, Peterborough, Cambridgeshire
> PE1 1JY
>
> If you have a Freedom of Information/Environmental Information request
> please refer to our website page
>
> This message has been checked for all known viruses by JNCC delivered
> through the MessageLabs Virus Control Centre.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>


-- 
Gregory (Greg) L. Snow Ph.D.
538280@gmail.com

	[[alternative HTML version deleted]]

