Re: [R] help with grouping data and calculating the means

2018-11-15 Thread Anthoni, Peter (IMK)
Hi Sasa, Those latitude look equidistant with a separation of 0.05. I guess you want to calculate the zonal mean along the latitude, right? #estimate the lower and upper latitude for the cut lat.dist=0.05 #equidistant spacing along latitude lat.min=min(df$LAT,na.rm=T)-lat.dist/2 lat.max=max(df$LA

Re: [R] Help needed with aggregate or other solution

2017-10-26 Thread Anthoni, Peter (IMK)
Hi Thomas, Would this work: res1=aggregate(dta[,"fcst"],by=list(basistime=dta[,"basistime"]),FUN=max) mm=match(paste(res1[,"basistime"],res1[,"x"]),paste(dta[,"basistime"],dta[,"fcst"])) dta[mm,] > dta[mm,] date basistime fcst usgs 20 2012-01-30 12:00:00 2012-01-25 15:0

Re: [R] submitting R scripts with command_line_arguments to PBS HPC clusters

2017-07-11 Thread Anthoni, Peter (IMK)
Hi, The problem is most likely, you need to call a R CMD BATCH with your arguments and the R-script inside of a shell script that you submit to your qsub. Unfortunately we don't use qsub anymore so can't test it, but it should be as follows: R-script eg. test.R: > ##First read in the arguments

Re: [R] Efficient swapping

2017-07-07 Thread Anthoni, Peter (IMK)
how about gdata functions? set.seed(1) (tmp <- data.frame(x = 1:10, R1 = sample(LETTERS[1:5], 10, replace = TRUE), R2 = sample(LETTERS[2:6], 10, replace = TRUE))) tmp.orig=tmp library(gdata) bigMap=mapLevels(x=list(factor(tmp[,"R1"]),factor(tmp[,"R2"])),combine = T,codes=FALSE) mapLevels(tmp[,"

Re: [R] expand gridded matrix to higher resolution

2017-07-05 Thread Anthoni, Peter (IMK)
; > You probably ought to be using the raster package. See the CRAN Spatial Task > View. > -- > Sent from my phone. Please excuse my brevity. > > On July 5, 2017 12:20:28 AM PDT, "Anthoni, Peter (IMK)" > wrote: >> Hi all, >> (if me email goes out a

Re: [R] expand gridded matrix to higher resolution

2017-07-05 Thread Anthoni, Peter (IMK)
Hi Jim, thanks that works like a charm. cheers Peter > On 5. Jul 2017, at 12:01, Jim Lemon wrote: > > Hi Peter, > > apply(t(apply(mm,1,rep,each=3)),2,rep,each=3) > > Jim > > On Wed, Jul 5, 2017 at 5:20 PM, Anthoni, Peter (IMK) > wrote: >> Hi all, &g

[R] expand gridded matrix to higher resolution

2017-07-05 Thread Anthoni, Peter (IMK)
Hi all, (if me email goes out as html, than my email client don't do as told, and I apologies already.) We need to downscale climate data and therefore first need to expand the climate from 0.5deg to the higher resolution 10min, before we can add high resolution deviations. We basically need to

Re: [R] Help: ifelse selection for x,y coordinates

2017-06-22 Thread Anthoni, Peter (IMK)
Hi Celine, what about removing the unwanted after you made the x and y x<-x[x>0] # or x<-x[x>0&&y>0], ditto for y, x[x!=""] in your ifelse (... ,"") case if x and y will not have the same length afterwards you need to make that list thingy. cheers Peter On 23. Jun 2017, at 07:30, Céline Lü

Re: [R] memory problem

2017-05-02 Thread Anthoni, Peter (IMK)
Hi Amit, Is the file gzipped or extracted? if you read the plain text file, try to gzip it and make a read.table on the gzipped file, the read.table can handle gzipped files at least on linux and mac OS, not sure about windows. cheers Peter > On 2. May 2017, at 18:59, Amit Sengupta via R-hel

Re: [R] asking for help

2017-04-25 Thread Anthoni, Peter (IMK)
Hi, the cut function might be helpful. vec=1: 163863 fcut=cut(vec,seq(1, 163863+1,by= 6069),include.lowest = T,right=F) aggregate(vec,by=list(fcut),min) aggregate(vec,by=list(fcut),max) cheers Peter On 25. Apr 2017, at 14:33, PIKAL Petr mailto:petr.pi...@precheza.cz>> wrote: Hi -Origin

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-27 Thread Anthoni, Peter (IMK)
Hi Paul, match might help, but without a real data sample, it is hard to check if the following might work. mm=match(df.col378[,"Date"],df.col362[,"Date"]) #mm will have NAs, where there is no matching date in df.col362 #and have the index of the match, where the two dates match new.df=cbind(df.

Re: [R] Aggregate matrix in a 2 by 2 manor

2016-07-31 Thread Anthoni, Peter (IMK)
16 2824.557 100 b > > > On Sat, 30 Jul 2016, Jeff Newmiller wrote: > >> For the record, the array.apply code can be fixed as below, but then it is >> slower than the expand.grid version. >> >> aggregate.nx.ny.array.apply <- function(dta,nx=2,ny=2, FUN=

Re: [R] Aggregate matrix in a 2 by 2 manor

2016-07-30 Thread Anthoni, Peter (IMK)
; cells <- as.matrix(expand.grid(ilat, ilon)) >>>> blocks <- apply(cells, 1, function(x) tst[x[1]:(x[1]+1), >>> x[2]:(x[2]+1)]) >>>> block.means <- colMeans(blocks) >>>> tst_2x2 <- matrix(block.means, 2, 4) >>>> tst_2x2 >>

[R] Aggregate matrix in a 2 by 2 manor

2016-07-27 Thread Anthoni, Peter (IMK)
Hi all, I need to aggregate some matrix data (1440x720) to a lower dimension (720x360) for lots of years and variables I can do double for loop, but that will be slow. Anybody know a quicker way? here an example with a smaller matrix size: tst=matrix(1:(8*4),ncol=8,nrow=4) tst_2x2=matrix(NA,nc

Re: [R] Extracting point data using longitude and latitude from netcdf file using R

2016-01-09 Thread Anthoni, Peter (IMK)
Hi Peter, the start in nc_varget requires a latitude and longitude index, not the latitude and longitude in double format. So you need to figure out what index your latitude and longitude correspond to, which will depends on what data are in your netCDF. it might have looked like that it worked

Re: [R] assigning values to elements of matrixes

2015-12-23 Thread Anthoni, Peter (IMK)
Hi, How about the following: foo2 <- function(s,i,j,value) { M = get(paste("M_",s,sep="")) M[i,j] = value assign(paste("M_",s,sep=""),M, envir = .GlobalEnv) } foo2("a",1,2,15) cheers Peter > On 23 Dec 2015, at 09:44, Matteo Richiardi wrote: > > I am following the example I find on ?ass

Re: [R] Multiple if function

2015-09-15 Thread Anthoni, Peter (IMK)
Hi, I guess this might work too and might be quite speedy: ASBclass = factor(c(1,2,2,3,2,1)) Flow = c(1,1,1,1,1,1) mult = ((ASBclass==1) * 0.1 + (ASBclass==2) * 0.15 + (ASBclass==3) * 0.2) deviation = mult * Flow or with the more complex arithmetic: deviation = ((ASBclass==1) * (Flow*2) + (ASB

Re: [R] Multiple if function

2015-09-15 Thread Anthoni, Peter (IMK)
Hi Maria, Why not exploit some simple boolean facts (FALSE=0, TRUE=1) in your calculation, so ASBclass = c(1,2,2,3,2,1) Flow = c(1,1,1,1,1,1) factor = ((ASBclass==1) * 0.1 + (ASBclass==2) * 0.15 + (ASBclass==3) * 0.2) deviation = factor * Flow cheers Peter > On 15 Sep 2015, at 12:56, Maria

Re: [R] Error -> cannot open file 'specdata/001.csv': No such file or directory; Windows 8, R Version 3.2.1

2015-08-16 Thread Anthoni, Peter (IMK)
Hi Nikita, To check whether the files are really there, run the following at the R prompt: getwd() list.files() > *C:/Users/acer/My Documents/specdata/rprog-data-specdata/specdata* Your working path looks like you either need to set it to: C:/Users/acer/My Documents/specdata/rprog-data-specda

Re: [R] Varying name of output tables from looped process of list of spdf objects

2015-07-27 Thread Anthoni, Peter (IMK)
Hi Cecilia, print(fnp) and print(a_10) are not exactly the same >> print(fnp) > $a_10 > class : SpatialPolygonsDataFrame vs. >> print(a_10) > class : SpatialPolygonsDataFrame Looks like mget returns a list. Can you try: fnp <- get(afiles[ifile])[1] print(fnp) #the $a_10 should b

Re: [R] Varying name of output tables from looped process of list of spdf objects

2015-07-27 Thread Anthoni, Peter (IMK)
Hi Cecilia, Alternative solution #... afiles <- ls(pattern= "a_") for (ifile in 1:length(afiles)) { fnp = mget(afiles[ifile]) #... do something with fnp outfile <- file.path("/Users/sisolarrosa/Documents/PhD/R_work/AF/IIC/conefor_inputs/", paste0("distances_", afiles[ifile], ".txt")); #..