[R] using cat to log to file with sapply

2018-02-14 Thread Alexander.Herr
Hi List, I am trying to write unsuccessfully to a logfile with cat. Here my example code: letters[1:5]->x logf<-"test.txt" cat('%%\n',file=logf) catf<-function(x,...,logfile='log.txt', append=TRUE){ cat(x,'\n', file=logfile, append=append)} testit<-function(x,...){ paste

[R] raster time series statistics

2018-03-05 Thread Alexander.Herr
Hi List, The following code returns an "Error in as.POSIXlt.character(x, tz, ...) : character string is not in a standard unambiguous format" require(raster) require(rts) require(stringi) r <- raster(ncol=100, nrow=100) values(r) <- runif(ncell(r)) list(ID=seq(1:24),month=rep(str_pad(1:12, pad

Re: [R] raster time series statistics

2018-03-05 Thread Alexander.Herr
Thanks Jim Still getting the same error for apply.montly Updated code: require(raster) require(rts) require(stringr) r <- raster(ncol=100, nrow=100) values(r) <- runif(ncell(r)) stack(r)->s r->rs for(i in 1:23){ rs[]<-r[]*i addLayer(s,rs)->s print(nlayers(s)) } dt<-list(ID=seq(1:24),month=rep

Re: [R] raster time series statistics

2018-03-05 Thread Alexander.Herr
Last line in the following (updated) code produces the error require(raster) require(rts) require(stringr) r <- raster(ncol=100, nrow=100) values(r) <- runif(ncell(r)) stack(r)->s r->rs for(i in 1:23){ rs[]<-r[]*i addLayer(s,rs)->s print(nlayers(s)) } dt<-list(ID=seq(1:24),month=rep(formatC(1:1

Re: [R] raster time series statistics

2018-03-05 Thread Alexander.Herr
It works if you use as.Date. But this defeates the purpose for the yearmon notion... require(raster) require(rts) require(stringr) r <- raster(ncol=100, nrow=100) values(r) <- runif(ncell(r)) stack(r)->s r->rs for(i in 1:23){ rs[]<-r[]*i addLayer(s,rs)->s print(nlayers(s)) } dt<-list(ID=seq(1

[R] adding new values to dataframe based on existing values in two columns

2016-07-21 Thread Alexander.Herr
Hiya, I am trying to assign minimum values to a dataframe based on existing columns. I can do this via loops, but surely R has much more elegant solutions... Here is my code: set.seed(666) xyz<-as.data.frame(cbind(x=rep(rpois(50,10),2)+1, y=rep(rpois(50,10),2)+1,z=runif(100, min=-3, max=40)))

Re: [R] adding new values to dataframe based on existing values in two columns

2016-07-24 Thread Alexander.Herr
Here is another solution using interaction, aggregate and merge: interaction(xyz[,1],xyz[,2])->nf #create a unique x.y grouping cbind(xyz[,1:2],nf) aggregate(xyz[,3],list(nf),min)->nmins names(nmins)<-c('nf','mins.1') xyz$nf<-nf merge(xyz,nmins, by='nf', all=TRUE)->nd head(nd)

[R] foreach {parallel} nested with for loop to update data.frame column

2016-08-03 Thread Alexander.Herr
Hi List, Trying to update a data.frame column within a foreach nested for loop ### trial data set.seed(666) xyz<-as.data.frame(cbind(x=rep(rpois(5000,10),2)+1, y=rep(rpois(5000,10),2)+1,z=round(runif(1, min=-3, max=40),2))) xyz$mins<-rep(NA, nrow(xyz)) cl<-makeCluster(16) #adjust to your

Re: [R] foreach {parallel} nested with for loop to update data.frame column

2016-08-04 Thread Alexander.Herr
Hiya, Yes that would work, also an aggregate with merge can work, but I really would like to make this a parallel calculation with farming out the first loop to different workers and put the output together again into the data.frame with additional columns. This will speed up work with very larg

Re: [R] foreach {parallel} nested with for loop to update data.frame column

2016-08-04 Thread Alexander.Herr
Hiya, This now works... test<-foreach(i=unique(xyz[,1]), .combine=rbind, .verbose=T) %dopar% { for( j in unique(xyz[,2])) { xyz[xyz[,2] == j & xyz[,1] == i ,4]<-min(xyz[xyz[,2] == j & xyz[,1] == i,3]) nr=nrow(xyz[xyz[,2] == j & xyz[,1] == i ,4]) } retu

Re: [R] foreach {parallel} nested with for loop to update data.frame column

2016-08-08 Thread Alexander.Herr
Actually, you'll need to identify the values of the foreach loop in the for loop for it to work... require(doParallel) require(foreach) set.seed(666) xyz<-as.data.frame(cbind(x=rep(rpois(5,10),2)+1, y=rep(rpois(5,10),2)+1,z=round(runif(10, min=-3, max=40),2))) xyz$mins<-rep(NA, nrow(

[R] expressions from dataframe columns

2015-02-18 Thread Alexander.Herr
Hi List, I am trying to assign a large expression. It has about 140 lines of code, so of course this is cumbersome: list('10001'=list(panel=c(PanelOne=944), seltype='Equal'), '10002'=list(panel=c(PanelOne=454), seltype='Equal'), '10003'=list(panel=c(PanelOne=1210), seltype='Equal'), '10004'=list(

[R] hierarchical clustering - variable selection

2009-06-30 Thread Alexander.Herr
Hi List, I am looking for a procedure that allows selection of variables in a clustering attempt. Specifically I am searching for a way of selecting out noise variables from a set of numeric/categorical variables (or of course selecting "non-noise" variables). The procedure should work wit

Re: [R] hierarchical clustering - variable selection

2009-07-01 Thread Alexander.Herr
Maybe I haven't been sufficiently clear on what I am after: I am looking for R adaptations of approaches (relevant to hierarchical clustering of categorical variables) described in Steinley and Brusco 2008 "Selection of variables in cluster analysis: an empirical comparison of eight procedure

[R] stepwise variable selection method wanted

2009-07-30 Thread Alexander.Herr
Hi List, I am looking for a variable selection procedure with a forward-backward selection method. Firstly, it is meant to work with the cophenetic correlation coefficient (CPCC) and intended to find the variable combination with the highest cophenetic correlation. Secondly, it is aimed at Gower

[R] rbugs on linux and wine

2008-04-20 Thread Alexander.Herr
bin/WinBugs14/winbugs.exe starts up winbugs. I am running opensuse 10.3 with R 2.6.2 (2007-11-26), winbugs 1.4.3 (6th August, 2007). Any ideas on what goes wrong? Thanks Herry Dr Alexander Herr - Herry CSIRO, Sustainable Ecosystems Gungahlin Homestead Bellenden Street GPO Box 284 Crace, ACT 2601

[R] readAsciiGrid memory issues

2008-12-03 Thread Alexander.Herr
Hi List, I am unable to read in a 7.8Gb ascii grid using readAsciiGrid {maptools} - R runs out of memory. I have 4Gb ram and 4Gb swap, so things are getting tight. I am wondering if anyone has alternative options (preferably with example) that enable to read in large grids, do some calculation

[R] fontsize in mosaic plot lables

2007-09-18 Thread Alexander.Herr
Hi List, I am trying unsucessfully to modify the fontsize of lables in mosaic: require(vcd) mosaic(Titanic, pop=FALSE, labeling_args=list(rot_labels=c(bottom=90,top=90), set_varnames = c(Sex = "Gender"), gp_text=gpar(fontsize=20))) #can't get it to resize text tab <- ifelse(Tita

Re: [R] fontsize in mosaic plot lables

2007-09-19 Thread Alexander.Herr
Thanks Patric, mosaic{vdc} takes gpar parameters. So cex.axis does not work for mosaic(Titanic, pop=FALSE, labeling_args=list(rot_labels=c(bottom=90,top=90),cex.axis=0.5)) or mosaic(Titanic, pop=FALSE, labeling_args=list(rot_labels=c(bottom=90,top=90)),cex.axis=0.5) However, mosaic(Titanic, po

[R] special characters in linux using dev.print

2007-10-07 Thread Alexander.Herr
Hi List, I want to print ± in a lattice graph label. This works in windows, but the linux version has problems - it cannot translate the character. Error is "invalid input in mbcsToLatin1". I use the standard encoding and also dev.print(file="filename",dev=pdf, encoding="PDFDoc.enc") I am afr

Re: [R] special characters in linux using dev.print

2007-10-08 Thread Alexander.Herr
Thanks Brian, I got lost with the coding between windows and linux. I used the ± (Windows: Alt-0177, instead of "\u00B1") in a code writen under windows and than used on linux. eg: plot(1:10) text(3,8,paste("±", "alt-numeric 0177 works only in windows",sep="")) text(8,3,paste("\u00B1"," \\u00B

[R] adjust labels in plot:terminal_panel {party}

2007-10-24 Thread Alexander.Herr
Hi List, I am unsuccessfully trying to beautify barplot outputs from ctree. For example I would like to rotate x-axis lables and resize/change font/type. mtree <- ctree(ME ~ ., data = mammoexp) plot(mtree,terminal_panel=node_barplot(mtree,col="black",fill=NULL, beside=TRUE, ylines=NULL,