Re: [R] assign NA to rows by test on multiple columns of a data frame

2017-11-22 Thread Massimo Bressan
yes, it works, even if I do not really get how and why it's working the combination of logical results (could you provide some insights for that?) moreover, and most of all, I was hoping for a compact solution because I need to deal with MANY columns (more than 40) in data frame with the same ba

Re: [R] ccomp Composition and ggtern plot...

2017-11-22 Thread Jeff Newmiller
I have no clue what this package is for, but reading the help page for the ccomp function tells you that it returns a numeric vector or matrix. How do YOU want to display information from this numeric vector? That will determine how you would put it into a data frame. -- Sent from my phone. Ple

[R] Fw: modified mankendal

2017-11-22 Thread Elham Fakharizade via R-help
Hello DearI used modifiedmk package for trend analyses.this is my script  require(modifiedmk)X1<-read.table("c:/elham/first article/r/Spring_NDVI-1.txt",skip=2,header=FALSE)d=dim(X1) outMK<-matrix(-999,nrow=4,ncol=d[2])for (c in 1:d[2]){MK<-tfpwmk(X1[,c])outMK[1,c]<-getElement(MK,"S")outMK[2,c]

Re: [R] function pointers?

2017-11-22 Thread Duncan Murdoch
On 22/11/2017 11:29 AM, Paul Johnson wrote: We have a project that calls for the creation of a list of many distribution objects. Distributions can be of various types, with various parameters, but we ran into some problems. I started testing on a simple list of rnorm-based objects. I was a lit

Re: [R] assign NA to rows by test on multiple columns of a data frame

2017-11-22 Thread Bert Gunter
Do you mean like this: mydf <- within(mydf, { is.na(A)<- !A_flag is.na(B)<- !B_flag } ) > mydf A A_flag B B_flag 1 8 10 5 12 2 NA 0 6 9 3 10 1 NA 0 4 NA 0 1 5 5 5 2 NA 0 Cheers, Bert Bert Gunter "The trouble with h

[R] function pointers?

2017-11-22 Thread Paul Johnson
We have a project that calls for the creation of a list of many distribution objects. Distributions can be of various types, with various parameters, but we ran into some problems. I started testing on a simple list of rnorm-based objects. I was a little surprised at the RAM storage requirements,

Re: [R] mystery "158"

2017-11-22 Thread William Dunlap via R-help
I think the '[<-' function for atomic types doesn't pay attention to the class of the right hand side, only to its mode. It strips all the attributes of the RHS, including the class. > f <- function(x) { x[2] <- factor("z", levels=letters) ; x } > f(101:103) [1] 101 26 103 > f(c("One","Two","Thr

Re: [R] assign NA to rows by test on multiple columns of a data frame

2017-11-22 Thread Ek Esawi
Hi-- I too misread the question twice and i may have mistakenly posted non-text answer earlier. Below is a step by step solution that works provided that your real data frame has the same structure (alternative columns as in your example). You could combine all the steps in 2 statements. Best of

Re: [R] assign NA to rows by test on multiple columns of a data frame

2017-11-22 Thread Ek Esawi
OPS, Sorry i did not read the post carfully. Mine will not work if you have zeros on columns A and B.. But you could modify it to work for specific columns i believe. EK On Wed, Nov 22, 2017 at 8:37 AM, Ek Esawi wrote: > Hi *Massimo,* > > *Try this.* > > *a <- mydf==0mydf[a] <- NAHTHEK* > > On

Re: [R] assign NA to rows by test on multiple columns of a data frame

2017-11-22 Thread Ek Esawi
Hi *Massimo,* *Try this.* *a <- mydf==0mydf[a] <- NAHTHEK* On Wed, Nov 22, 2017 at 5:34 AM, Massimo Bressan < massimo.bres...@arpa.veneto.it> wrote: > > > Given this data frame (a simplified, essential reproducible example) > > > > > A<-c(8,7,10,1,5) > > A_flag<-c(10,0,1,0,2) > > B<-c(5,6,2,1,0

Re: [R] assign NA to rows by test on multiple columns of a data frame

2017-11-22 Thread Rui Barradas
Hello, Sorry, I obviously read in a hurry. icol <- grepl("flag", names(mydf)) is.na(mydf[!icol]) <- mydf[icol] == 0 mydf # A A_flag B B_flag #1 8 10 5 12 #2 NA 0 6 9 #3 10 1 NA 0 #4 NA 0 1 5 #5 5 2 NA 0 Hope this helps, Rui Barradas O

Re: [R] assign NA to rows by test on multiple columns of a data frame

2017-11-22 Thread Massimo Bressan
...well, I don't think this is exactly the expected result (see my post) to be noted that the columns affected should be "A" and "B" thanks for the help max - Messaggio originale - Da: "Rui Barradas" A: "Massimo Bressan" , "r-help" Inviato: Mercoledì, 22 novembre 2017 11:49:08 Oggett

[R] ccomp Composition and ggtern plot...

2017-11-22 Thread Levent TERLEMEZ via R-help
Dear Users, I would like to use compositions package with ggplot/ggtern, other composition classes of compositional package can be used with ggtern by converting to data frame but I could do anything with c(ount)comp class. Ggplot/ggtern can not recognise comp and also can not be converted to d

Re: [R] assign NA to rows by test on multiple columns of a data frame

2017-11-22 Thread Rui Barradas
Hello, Try the following. icol <- which(grepl("flag", names(mydf))) mydf[icol] <- lapply(mydf[icol], function(x){ is.na(x) <- x == 0 x }) mydf # A A_flag B B_flag #1 8 10 5 12 #2 7 NA 6 9 #3 10 1 2 NA #4 1 NA 1 5 #5 5 2 0 NA

[R] assign NA to rows by test on multiple columns of a data frame

2017-11-22 Thread Massimo Bressan
Given this data frame (a simplified, essential reproducible example) A<-c(8,7,10,1,5) A_flag<-c(10,0,1,0,2) B<-c(5,6,2,1,0) B_flag<-c(12,9,0,5,0) mydf<-data.frame(A, A_flag, B, B_flag) # this is my initial df mydf I want to get to this final situation i<-which(myd

Re: [R] How to produce rainfall maps

2017-11-22 Thread Michael Sumner
Fwiw the engine behind geom_raster needs explicit observation-per-row form for input (with no structural normalization), so conversion to points is perfectly proper here, albeit confusing in context. (It's closer to what graphics devices actually use ultimately, but the expansion is laid out very

Re: [R] mystery "158"

2017-11-22 Thread PIKAL Petr
Well, ?factor does not say anything about this behaviour (assigning numeric code instead of level of factor). And actually if you do assignment for whole vector the result is different (vector in data frame is changed to factor). > temp2$fff[1]<-vec[1] > head(temp2,2) pokus minuty fff 1 T42