Re: [R] How would I color points conditional on their value in a plot of a time series
> Eivind K Dovik > on Tue, 1 May 2018 23:18:51 +0200 writes: > You may also want to check this out: > plot(ttt, type = "p") > points(ttt, col = ifelse(ttt < 8, "black", "red")) > Eivind K. Dovik > Bergen, NO yes, indeed, or -- even nicer for a time series: using 'type = "c"' which many people don't know / have forgotten about: ttt <- ts(rpois(12, lambda = 8), start = c(2000, 1), freq = 4) plot (ttt, type = "c") points(ttt, col = ifelse(ttt < 8, "black", "red")) Martin Maechler > On Tue, 1 May 2018, Christopher W Ryan wrote: >> Excellent! Worked like a charm. Thanks. >> >> --Chris Ryan >> >> On Tue, May 1, 2018 at 4:33 PM, William Dunlap wrote: >> >>> The ts method for plot() is quirky. You can use the default method: >>> >>> plot(as.vector(time(ttt)), as.vector(ttt), type = "p", col=ifelse(ttt<8, >>> "black", "red")) >>> >>> >>> Bill Dunlap >>> TIBCO Software >>> wdunlap tibco.com >>> >>> On Tue, May 1, 2018 at 1:17 PM, Christopher W Ryan >>> wrote: >>> How would I color points conditional on their value in a plot of a time series. Something like this: ## demonstration data ttt <- ts(rpois(12, lambda = 8), start = c(2000, 1), freq = 4) ttt plot(ttt, type = "p") ## doesn't work--all points the same color plot(ttt, type = "p", col = ifelse(ttt < 8, "black", "red")) ## also doesn't work--all points the same color q <- as.numeric(ttt) q plot(ttt, type = "p", col = ifelse(q < 8, "black", "red")) ## works OK with a simple, non-time-series scatterplot, as in sss <- data.frame(x = rpois(12, lambda = 8), y = rnorm(12, mean = 100, sd = 25)) with(sss, plot(y ~ x, col = ifelse(y > 100, "black", "red"))) ## but I am missing something about time series. Thanks. --Chris Ryan Broome County Health Department and Binghamton University Binghamton, NY [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posti ng-guide.html and provide commented, minimal, self-contained, reproducible code. >>> >>> >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Merging dataframes
Thanks - Peter, Eivind, Rui Sorry, I perhaps could not explain it properly in the first go. Trying to simplify it here with an example - Say I have two dataframes as below that are NOT equally-sized data frames (i.e., number of columns are different in each table): Table_A: Email Name Phone a...@gmail.com John Chan 0909 b...@yahoo.com Tim Ma89089 .. Table_B: Email Name SexPhone a...@gmail.comJohn ChanM 0909 k...@hotmail.com Rosy Kim F 7779 . Now, I have used - merge (Table_A, Table_B, by="Email", all = FALSE)) - to find only the rows that match from these data frames - based on Email as primary key. Further, I am also interested (using "Email" as the common key) which rows from Table_A did not match with Table_B. I am not sure how to do this here. Thanks and regards, Chintanu On Tue, May 1, 2018 at 8:48 PM, Rui Barradas wrote: > Hello, > > Is it something like this that you want? > > x <- data.frame(a = c(1:3, 5, 5:10), b = c(1:7, 7, 9:10)) > y <- data.frame(a = 1:10, b = 1:10) > > which(x != y, arr.ind = TRUE) > > > Hope this helps, > > Rui Barradas > > > On 5/1/2018 11:35 AM, Chintanu wrote: > >> Hi, >> >> >> May I please ask how I do the following in R. Sorry - this may be trivial, >> but I am struggling here for this. >> >> >> >> For two dataframes (A and B), I wish to identify (based on a primary >> key-column present in both A & B) - >> >> 1. Which records (rows) of A did not match with B, and >> >> >> >> 2. Which records of B did not match with A ? >> >> >> >> I came across a setdt function while browsing, but when I tried it, it >> says >> - Could not find function "setdt". >> >> >> >> Overall, if there is any way of doing it (preferably in some simplified >> way), please advise. >> >> >> Many thanks in advance. >> >> >> regards, >> >> Tito >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posti >> ng-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Merging dataframes
Hi, I'll coded your example into R code: Table_A <- c('a...@gmail.com', 'John Chan', '0909') Table_A <- rbind(Table_A, c('b...@yahoo.com', 'Tim Ma', '89089')) colnames(Table_A) <- c('Email', 'Name', 'Phone') Table_A Table_B <- c('a...@gmail.com', 'John Chan', 'M', '0909') Table_B <- rbind(Table_B, c('k...@hotmail.com', 'Rosy Kim', 'F', '7779')) colnames(Table_B) <- c('Email', 'Name', 'Sex', 'Phone') Table_B Did you have a look at this one? Table_C <- merge (Table_A, Table_B, by="Email", all = TRUE) Table_C[is.na(Table_C$Name.y),] Table_C[is.na(Table_C$Name.x),] Table_C contains all data from Table_A and Table_B. The key.x is NA if the row comes from Table_B and key.y is NA if the row comes from Table_A. Best, Robin On 05/02/2018 11:38 AM, Chintanu wrote: > Thanks - Peter, Eivind, Rui > > > Sorry, I perhaps could not explain it properly in the first go. > > Trying to simplify it here with an example - Say I have two dataframes as > below that are NOT equally-sized data frames (i.e., number of columns are > different in each table): > > > > Table_A: > > Email Name Phone > > a...@gmail.com John Chan 0909 > > b...@yahoo.com Tim Ma89089 > > .. > > > > Table_B: > > Email Name SexPhone > > a...@gmail.comJohn ChanM 0909 > > k...@hotmail.com Rosy Kim F 7779 > > . > > > > Now, I have used - > > merge (Table_A, Table_B, by="Email", all = FALSE)) > > > > - to find only the rows that match from these data frames - based on Email > as primary key. > > > > Further, I am also interested (using "Email" as the common key) which rows > from Table_A did not match with Table_B. > > I am not sure how to do this here. > > Thanks and regards, > Chintanu > > > > On Tue, May 1, 2018 at 8:48 PM, Rui Barradas wrote: > >> Hello, >> >> Is it something like this that you want? >> >> x <- data.frame(a = c(1:3, 5, 5:10), b = c(1:7, 7, 9:10)) >> y <- data.frame(a = 1:10, b = 1:10) >> >> which(x != y, arr.ind = TRUE) >> >> >> Hope this helps, >> >> Rui Barradas >> >> >> On 5/1/2018 11:35 AM, Chintanu wrote: >> >>> Hi, >>> >>> >>> May I please ask how I do the following in R. Sorry - this may be trivial, >>> but I am struggling here for this. >>> >>> >>> >>> For two dataframes (A and B), I wish to identify (based on a primary >>> key-column present in both A & B) - >>> >>> 1. Which records (rows) of A did not match with B, and >>> >>> >>> >>> 2. Which records of B did not match with A ? >>> >>> >>> >>> I came across a setdt function while browsing, but when I tried it, it >>> says >>> - Could not find function "setdt". >>> >>> >>> >>> Overall, if there is any way of doing it (preferably in some simplified >>> way), please advise. >>> >>> >>> Many thanks in advance. >>> >>> >>> regards, >>> >>> Tito >>> >>> [[alternative HTML version deleted]] >>> >>> __ >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posti >>> ng-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >>> > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Dr. Robin Haunschild Max Planck Institute for Solid State Research Heisenbergstr. 1 D-70569 Stuttgart (Germany) phone: +49 (0) 711-689-1285 fax: +49 (0) 711-689-1292 email: r.haunsch...@fkf.mpg.de http://www.fkf.mpg.de/ivs __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Merging dataframes
Have a look at anti_join() from the dplyr package. It does exactly what you want. Here is an example based on the code of Robin Table_A <- as.data.frame(Table_A, stringsAsFactors = FALSE)That is Table_B <- as.data.frame(Table_B, stringsAsFactors = FALSE) library(dplyr) anti_join(Table_A, Table_B, by = "Email") anti_join(Table_B, Table_A, by = "Email") Best regards, ir. Thierry Onkelinx Statisticus / Statistician Vlaamse Overheid / Government of Flanders INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND FOREST Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance thierry.onkel...@inbo.be Havenlaan 88 bus 73, 1000 Brussel www.inbo.be /// To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey /// 2018-05-02 13:23 GMT+02:00 Dr. Robin Haunschild : > Hi, > > I'll coded your example into R code: > > Table_A <- c('a...@gmail.com', 'John Chan', '0909') > Table_A <- rbind(Table_A, c('b...@yahoo.com', 'Tim Ma', '89089')) > colnames(Table_A) <- c('Email', 'Name', 'Phone') > Table_A > > Table_B <- c('a...@gmail.com', 'John Chan', 'M', '0909') > Table_B <- rbind(Table_B, c('k...@hotmail.com', 'Rosy Kim', 'F', '7779')) > colnames(Table_B) <- c('Email', 'Name', 'Sex', 'Phone') > Table_B > > Did you have a look at this one? > Table_C <- merge (Table_A, Table_B, by="Email", all = TRUE) > Table_C[is.na(Table_C$Name.y),] > Table_C[is.na(Table_C$Name.x),] > > Table_C contains all data from Table_A and Table_B. The key.x is NA if > the row comes from Table_B and key.y is NA if the row comes from Table_A. > > Best, Robin > > > On 05/02/2018 11:38 AM, Chintanu wrote: >> Thanks - Peter, Eivind, Rui >> >> >> Sorry, I perhaps could not explain it properly in the first go. >> >> Trying to simplify it here with an example - Say I have two dataframes as >> below that are NOT equally-sized data frames (i.e., number of columns are >> different in each table): >> >> >> >> Table_A: >> >> Email Name Phone >> >> a...@gmail.com John Chan 0909 >> >> b...@yahoo.com Tim Ma89089 >> >> .. >> >> >> >> Table_B: >> >> Email Name SexPhone >> >> a...@gmail.comJohn ChanM 0909 >> >> k...@hotmail.com Rosy Kim F 7779 >> >> . >> >> >> >> Now, I have used - >> >> merge (Table_A, Table_B, by="Email", all = FALSE)) >> >> >> >> - to find only the rows that match from these data frames - based on Email >> as primary key. >> >> >> >> Further, I am also interested (using "Email" as the common key) which rows >> from Table_A did not match with Table_B. >> >> I am not sure how to do this here. >> >> Thanks and regards, >> Chintanu >> >> >> >> On Tue, May 1, 2018 at 8:48 PM, Rui Barradas wrote: >> >>> Hello, >>> >>> Is it something like this that you want? >>> >>> x <- data.frame(a = c(1:3, 5, 5:10), b = c(1:7, 7, 9:10)) >>> y <- data.frame(a = 1:10, b = 1:10) >>> >>> which(x != y, arr.ind = TRUE) >>> >>> >>> Hope this helps, >>> >>> Rui Barradas >>> >>> >>> On 5/1/2018 11:35 AM, Chintanu wrote: >>> Hi, May I please ask how I do the following in R. Sorry - this may be trivial, but I am struggling here for this. For two dataframes (A and B), I wish to identify (based on a primary key-column present in both A & B) - 1. Which records (rows) of A did not match with B, and 2. Which records of B did not match with A ? I came across a setdt function while browsing, but when I tried it, it says - Could not find function "setdt". Overall, if there is any way of doing it (preferably in some simplified way), please advise. Many thanks in advance. regards, Tito [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posti ng-guide.html and provide commented, minimal, self-contained, reproducible code. >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.et
[R] Converting a list to a data frame
I suspect this is pretty easy, but I'm having trouble figuring it out. Basically, I have a list of data frames such as the following example: list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) I would like to turn this into data frame where the list elements are essentially rbind'ed together and the element name becomes a new variable. For example, I would like to turn the list above into a data frame that looks like this: data.frame(type=c("A","A","B","B"),x=c(1:2,5:6),y=c(3:4,7:8)) Appreciate any pointers. Kevin -- Kevin E. Thorpe Head of Biostatistics, Applied Health Research Centre (AHRC) Li Ka Shing Knowledge Institute of St. Michael's Hospital Assistant Professor, Dalla Lana School of Public Health University of Toronto email: kevin.tho...@utoronto.ca Tel: 416.864.5776 Fax: 416.864.3016 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Converting a list to a data frame
Hi Kevin, There is probably a better way, but it can be done in two steps like this temp <- list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) temp <- lapply(names(temp), function(n, temp) { temp[[n]]$type <- n return(temp[[n]]) }, temp = temp) do.call(rbind, temp) On Wed, May 2, 2018 at 1:11 PM, Kevin E. Thorpe wrote: > I suspect this is pretty easy, but I'm having trouble figuring it out. > Basically, I have a list of data frames such as the following example: > > list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) > > I would like to turn this into data frame where the list elements are > essentially rbind'ed together and the element name becomes a new variable. > For example, I would like to turn the list above into a data frame that > looks like this: > > data.frame(type=c("A","A","B","B"),x=c(1:2,5:6),y=c(3:4,7:8)) > > Appreciate any pointers. > > Kevin > > -- > Kevin E. Thorpe > Head of Biostatistics, Applied Health Research Centre (AHRC) > Li Ka Shing Knowledge Institute of St. Michael's Hospital > Assistant Professor, Dalla Lana School of Public Health > University of Toronto > email: kevin.tho...@utoronto.ca Tel: 416.864.5776 Fax: 416.864.3016 > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posti > ng-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Converting a list to a data frame
> x1 <- do.call(rbind, c(x, list(make.row.names=FALSE))) > x2 <- cbind(type=rep(names(x), vapply(x, nrow, 0)), x1) > str(x2) 'data.frame': 4 obs. of 3 variables: $ type: Factor w/ 2 levels "A","B": 1 1 2 2 $ x : int 1 2 5 6 $ y : int 3 4 7 8 Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, May 2, 2018 at 10:11 AM, Kevin E. Thorpe wrote: > I suspect this is pretty easy, but I'm having trouble figuring it out. > Basically, I have a list of data frames such as the following example: > > list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) > > I would like to turn this into data frame where the list elements are > essentially rbind'ed together and the element name becomes a new variable. > For example, I would like to turn the list above into a data frame that > looks like this: > > data.frame(type=c("A","A","B","B"),x=c(1:2,5:6),y=c(3:4,7:8)) > > Appreciate any pointers. > > Kevin > > -- > Kevin E. Thorpe > Head of Biostatistics, Applied Health Research Centre (AHRC) > Li Ka Shing Knowledge Institute of St. Michael's Hospital > Assistant Professor, Dalla Lana School of Public Health > University of Toronto > email: kevin.tho...@utoronto.ca Tel: 416.864.5776 Fax: 416.864.3016 > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posti > ng-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Converting a list to a data frame
On Wed, 2 May 2018, Kevin E. Thorpe wrote: I suspect this is pretty easy, but I'm having trouble figuring it out. Basically, I have a list of data frames such as the following example: list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) I would like to turn this into data frame where the list elements are essentially rbind'ed together and the element name becomes a new variable. For example, I would like to turn the list above into a data frame that looks like this: data.frame(type=c("A","A","B","B"),x=c(1:2,5:6),y=c(3:4,7:8)) Appreciate any pointers. Kevin Hi, Kevin. Here's code that will generate your desired data frame. # List as provided thelist <- list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) thelist # Creating the type-vector type <- c() for(i in 1:length(thelist)){ type <- c(type, rep(names(thelist)[i], sapply(thelist, nrow)[i])) } # Creating the data frame df <- data.frame(type, do.call(rbind.data.frame, c(thelist, make.row.names = FALSE))) df Kind regards, Eivind K. Dovik Bergen, NO -- Kevin E. Thorpe Head of Biostatistics, Applied Health Research Centre (AHRC) Li Ka Shing Knowledge Institute of St. Michael's Hospital Assistant Professor, Dalla Lana School of Public Health University of Toronto email: kevin.tho...@utoronto.ca Tel: 416.864.5776 Fax: 416.864.3016 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Converting a list to a data frame
Another approach: library(tidyr) L <- list( A = data.frame( x=1:2, y=3:4 ) , B = data.frame( x=5:6, y=7:8 ) ) D <- data.frame( Type = names( L ) , stringsAsFactors = FALSE ) D$data <- L unnest(D, data) #> Type x y #> 1A 1 3 #> 2A 2 4 #> 3B 5 7 #> 4B 6 8 On Wed, 2 May 2018, Eivind K. Dovik wrote: On Wed, 2 May 2018, Kevin E. Thorpe wrote: I suspect this is pretty easy, but I'm having trouble figuring it out. Basically, I have a list of data frames such as the following example: list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) I would like to turn this into data frame where the list elements are essentially rbind'ed together and the element name becomes a new variable. For example, I would like to turn the list above into a data frame that looks like this: data.frame(type=c("A","A","B","B"),x=c(1:2,5:6),y=c(3:4,7:8)) Appreciate any pointers. Kevin Hi, Kevin. Here's code that will generate your desired data frame. # List as provided thelist <- list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) thelist # Creating the type-vector type <- c() for(i in 1:length(thelist)){ type <- c(type, rep(names(thelist)[i], sapply(thelist, nrow)[i])) } # Creating the data frame df <- data.frame(type, do.call(rbind.data.frame, c(thelist, make.row.names = FALSE))) df Kind regards, Eivind K. Dovik Bergen, NO -- Kevin E. Thorpe Head of Biostatistics, Applied Health Research Centre (AHRC) Li Ka Shing Knowledge Institute of St. Michael's Hospital Assistant Professor, Dalla Lana School of Public Health University of Toronto email: kevin.tho...@utoronto.ca Tel: 416.864.5776 Fax: 416.864.3016 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] using apply
Hi I have 3 dataframes, a,b,c with 0/1 values...i have to check a condition for dataframe a and b and then input the rows ids to datframe c . In the if condition, I AND the 2 rows of from a and b and then see if the result is equal to one of them. I have done this using a for loop, however, it takes a long time to execute with larger dataset..Can you help me do it using apply function so that i can do it faster? a V1.x V2.x V3.x V1.y V2.y V3.y 1110101 2101101 3111101 4000101 b V1 V2 V3 V4 V5 V6 1 1 0 1 1 0 0 2 1 0 1 0 0 0 c xy 1 21 2 22 3 31 4 32 for(i in 1:nrow(a)){ for(j in 1:nrow(b)){ if(all((a[i,]&b[j,])==b[j,])) { c[nrow(c)+1, ]<-c(paste(i,j) } } } Thanks, Neha [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Converting a list to a data frame
On 05/02/2018 07:11 PM, Kevin E. Thorpe wrote: I suspect this is pretty easy, but I'm having trouble figuring it out. Basically, I have a list of data frames such as the following example: list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) I would like to turn this into data frame where the list elements are essentially rbind'ed together and the element name becomes a new variable. For example, I would like to turn the list above into a data frame that looks like this: data.frame(type=c("A","A","B","B"),x=c(1:2,5:6),y=c(3:4,7:8)) Appreciate any pointers. Hi Kevin, data.table::rbindlist does exactly what you want in a very efficient way: library(data.table) dat <- list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) rbindlist(dat, idcol = "type") Regards, Denes Kevin __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using apply
Hi Neha, Perhaps merge() from base or join from dplyr is what you are looking for. data. table could also be interesting. Hth Ulrik On Wed, 2 May 2018, 21:28 Neha Aggarwal, wrote: > Hi > > I have 3 dataframes, a,b,c with 0/1 values...i have to check a condition > for dataframe a and b and then input the rows ids to datframe c . In the if > condition, I AND the 2 rows of from a and b and then see if the result is > equal to one of them. > I have done this using a for loop, however, it takes a long time to execute > with larger dataset..Can you help me do it using apply function so that i > can do it faster? > > a > V1.x V2.x V3.x V1.y V2.y V3.y > 1110101 > 2101101 > 3111101 > 4000101 > > b > V1 V2 V3 V4 V5 V6 > 1 1 0 1 1 0 0 > 2 1 0 1 0 0 0 > > c > xy > 1 21 > 2 22 > 3 31 > 4 32 > > for(i in 1:nrow(a)){ > for(j in 1:nrow(b)){ > if(all((a[i,]&b[j,])==b[j,])) > { c[nrow(c)+1, ]<-c(paste(i,j) > } > } > } > > > Thanks, > Neha > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Converting a list to a data frame
Or add the type column first and then rbind: x <- list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) x2 <- do.call(rbind, lapply(names(x), function(z) data.frame(type=z, dat[[z]]))) David L Carlson Department of Anthropology Texas A&M University College Station, TX 77843-4352 -Original Message- From: R-help On Behalf Of William Dunlap via R-help Sent: Wednesday, May 2, 2018 12:28 PM To: Kevin E. Thorpe Cc: R Help Mailing List Subject: Re: [R] Converting a list to a data frame > x1 <- do.call(rbind, c(x, list(make.row.names=FALSE))) > x2 <- cbind(type=rep(names(x), vapply(x, nrow, 0)), x1) > str(x2) 'data.frame': 4 obs. of 3 variables: $ type: Factor w/ 2 levels "A","B": 1 1 2 2 $ x : int 1 2 5 6 $ y : int 3 4 7 8 Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, May 2, 2018 at 10:11 AM, Kevin E. Thorpe wrote: > I suspect this is pretty easy, but I'm having trouble figuring it out. > Basically, I have a list of data frames such as the following example: > > list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) > > I would like to turn this into data frame where the list elements are > essentially rbind'ed together and the element name becomes a new variable. > For example, I would like to turn the list above into a data frame > that looks like this: > > data.frame(type=c("A","A","B","B"),x=c(1:2,5:6),y=c(3:4,7:8)) > > Appreciate any pointers. > > Kevin > > -- > Kevin E. Thorpe > Head of Biostatistics, Applied Health Research Centre (AHRC) Li Ka > Shing Knowledge Institute of St. Michael's Hospital Assistant > Professor, Dalla Lana School of Public Health University of Toronto > email: kevin.tho...@utoronto.ca Tel: 416.864.5776 Fax: 416.864.3016 > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posti > ng-guide.html and provide commented, minimal, self-contained, > reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using apply
This might be faster. It uses apply() which is just another way of constructing a loop so it is not necessarily faster. We can vectorize the logical comparisons, but all() is not vectorized. Use dput() to share your data. That makes it easier to replicate your example: a <- structure(list(V1. = c(1, 1, 1, 0), V2.x = c(1, 0, 1, 0), V3.x = c(0, 1, 1, 0), V1.y = c(1, 1, 1, 1), V2.y = c(0, 0, 0, 0), V3.y = c(1, 1, 1, 1)), .Names = c("V1.x", "V2.x", "V3.x", "V1.y", "V2.y", "V3.y"), row.names = c(NA, -4L), class = "data.frame") b <- structure(list(V1 = c(1, 1), V2 = c(0, 0), V3 = c(1, 1), V4 = c(1, 0), V5 = c(0, 0), V6 = c(0, 0)), .Names = c("V1", "V2", "V3", "V4", "V5", "V6"), row.names = c(NA, -2L), class = "data.frame") # Generate the row indices that we need so we can vectorize the logical operation: idxa <- rep(1:4, each=2) idxb <- rep(1:2, 4) ab <- (a[idxa, ] & b[idxb, ]) == b[idxb, ] c <- cbind(idxa, idxb)[apply(ab, 1, all), ] c # idxa idxb # [1,]21 # [2,]22 # [3,]31 # [4,]32 David L Carlson Department of Anthropology Texas A&M University College Station, TX 77843-4352 -Original Message- From: R-help On Behalf Of Ulrik Stervbo Sent: Wednesday, May 2, 2018 3:49 PM To: Neha Aggarwal Cc: r-help@r-project.org Subject: Re: [R] using apply Hi Neha, Perhaps merge() from base or join from dplyr is what you are looking for. data. table could also be interesting. Hth Ulrik On Wed, 2 May 2018, 21:28 Neha Aggarwal, wrote: > Hi > > I have 3 dataframes, a,b,c with 0/1 values...i have to check a > condition for dataframe a and b and then input the rows ids to > datframe c . In the if condition, I AND the 2 rows of from a and b and > then see if the result is equal to one of them. > I have done this using a for loop, however, it takes a long time to > execute with larger dataset..Can you help me do it using apply > function so that i can do it faster? > > a > V1.x V2.x V3.x V1.y V2.y V3.y > 1110101 > 2101101 > 3111101 > 4000101 > > b > V1 V2 V3 V4 V5 V6 > 1 1 0 1 1 0 0 > 2 1 0 1 0 0 0 > > c > xy > 1 21 > 2 22 > 3 31 > 4 32 > > for(i in 1:nrow(a)){ > for(j in 1:nrow(b)){ > if(all((a[i,]&b[j,])==b[j,])) > { c[nrow(c)+1, ]<-c(paste(i,j) > } > } > } > > > Thanks, > Neha > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Converting a list to a data frame
Typo: dat[[z]] should be x[[z]]: x2 <- do.call(rbind, lapply(names(x), function(z) data.frame(type=z, x[[z]]))) x2 type x y 1A 1 3 2A 2 4 3B 5 7 4B 6 8 David C -Original Message- From: R-help On Behalf Of David L Carlson Sent: Wednesday, May 2, 2018 3:51 PM To: William Dunlap ; Kevin E. Thorpe Cc: r-help mailing list Subject: Re: [R] Converting a list to a data frame Or add the type column first and then rbind: x <- list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) x2 <- do.call(rbind, lapply(names(x), function(z) data.frame(type=z, dat[[z]]))) David L Carlson Department of Anthropology Texas A&M University College Station, TX 77843-4352 -Original Message- From: R-help On Behalf Of William Dunlap via R-help Sent: Wednesday, May 2, 2018 12:28 PM To: Kevin E. Thorpe Cc: R Help Mailing List Subject: Re: [R] Converting a list to a data frame > x1 <- do.call(rbind, c(x, list(make.row.names=FALSE))) > x2 <- cbind(type=rep(names(x), vapply(x, nrow, 0)), x1) > str(x2) 'data.frame': 4 obs. of 3 variables: $ type: Factor w/ 2 levels "A","B": 1 1 2 2 $ x : int 1 2 5 6 $ y : int 3 4 7 8 Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, May 2, 2018 at 10:11 AM, Kevin E. Thorpe wrote: > I suspect this is pretty easy, but I'm having trouble figuring it out. > Basically, I have a list of data frames such as the following example: > > list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) > > I would like to turn this into data frame where the list elements are > essentially rbind'ed together and the element name becomes a new variable. > For example, I would like to turn the list above into a data frame > that looks like this: > > data.frame(type=c("A","A","B","B"),x=c(1:2,5:6),y=c(3:4,7:8)) > > Appreciate any pointers. > > Kevin > > -- > Kevin E. Thorpe > Head of Biostatistics, Applied Health Research Centre (AHRC) Li Ka > Shing Knowledge Institute of St. Michael's Hospital Assistant > Professor, Dalla Lana School of Public Health University of Toronto > email: kevin.tho...@utoronto.ca Tel: 416.864.5776 Fax: 416.864.3016 > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posti > ng-guide.html and provide commented, minimal, self-contained, > reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Calling the curve function with a character object converted into an expression
Hi, Down a cascade of function calls, I want to use the curve function with an expression that is a variable. For various reason, this variable must be a character object and cannot be an expression as required by the curve function. How do I convert my variable into a expression that is accepted by curve? Thanks in advance for your help. ## The following attempts do not work myf <- '1+x^2' curve(myf, from = 0, to = 10) # obviously ! curve(parse(text=myf), from = 0, to = 10) # not sure why this does not work ## This works but does not feel elegant: eval(parse(text=sprintf('curve(%s, from = 0, to = 10)', myf))) __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] The stages of standard function evaluation
Dear R Help folks -- I have been trying to put together a list of the steps or stages of R function evaluation, with particular focus on those that have "standard" or "nonstandard" forms. This is both for my own edification and also because I am thinking of joining the world of R bloggers and have been trying to put together some draft posting that might be useful. I seem to have an affirmative genius for finding incorrect interpretations of R's evaluation rules; I'm trying to make that an asset. I am hoping that you can tell me: 1. Is this list complete, or are there additional stages I am missing? 2. Have I inserted one or more imaginary stages? 3. Are the terms I use below to name each stage appropriate, or are there other terms more widely used or recognizable? 4. Is the order correct? I begin each name with “Standard,” to express my belief that each of these things has a usual or default form, but also that (unless I am mistaken) almost none of them exist only in a single form true of all R functions. (I have marked with an asterisk a few evaluation steps that I think may always be followed). It is my ultimate goal (which I do not feel at all close to accomplishing) to determine a way to mechanically test for “standardness” along each of these dimensions, so that each function could be assigned a logical vector showing the ways that it is and is not standard. One thing I think is conceptually or procedurally difficult about this project is that I think “standardness” should be determined by what a function does, rather than by how it does it, so that a primitive function that takes unevaluated arguments positionally could still have standard matching, scoping, etc., by internal emulation. A related goal is to identify which evaluation steps most often use an alternative form, and perhaps determine if there is more than one such alternative. Finally, an easier short-term goal is simply to find instances of one or more function with standard and non-standard evaluation for each evaluation step. For the most part below I am treating the evaluation of closures as the standard from which “nonstandard” is defined. However, I do not assume that other kinds of functions are automatically nonstandard on any particular dimension below. Most of this comes from the R Language Definition, but there are numerous places where I am by no means certain that my interpretation is correct. I have highlighted some of these below with a “??”. I look forward to learning from you. Warmest regards, J. Andrew Hoerner ** Standard function recognition:* recognizing some or all of a string code as a function. (Part of code line parsing) *Standard environment construction:* construction of the execution environment, and of pointers to the calling and enclosing environments. *Standard function identification:* Get the name of the function, if any ** Standard f**unction scoping*: Search the current environment and then up the chain of enclosing environments until you find the first binding environment, an environment where the name of the function is bound, i.e. linked to a pointer to the function definition. The binding environment is usually (but not always) the same as the defining environment (i.e. the enclosing environment when the function is defined. Note that function lookup, unlike function argument lookup, necessarily starts from the calling environment, because a function does not know what it is – its formals, body, and environments – until it is found. Named functions are always found by scoping. R never learns "where" they are -- they have to be looked up each time. For this reason, anonymous functions must be used in place, and called by a function that takes a function as an argument, or by (function(formals){body})(actual args) *Standard f**unction **retrieval**:* load (??) the function, i.e. transfer the list (??) of formals and defaults and the list (??) of expressions that constitute the function body into the execution environment Note that the function body is parsed at the time the function is created (true?? Or is it parsed every time the function is called?) *Standard argument matching*: assignment of expressions and default arguments to formals via the usually-stated matching rulesIf matched positionall at call time, the name is scoped like an actual argument.. Note that giving an argument the same name as a formal when calling the function will only match it to that formal if matched positionally or by tag, not by name. *Standard a**rgument parsing:* Converts argument expressions into abstract syntax trees. “Standard” argument parsing and promise construction take place before the arguments are passed into the body. *Standard p**romise construction*: Assigning each name (including function names) in an AST to its binding the calling environment (if ordinary) or the execution environment (if default) (Am I right that the action here for calls and for names is essenti
Re: [R] Calling the curve function with a character object converted into an expression
Sebastian: This is somewhat arcane, perhaps even a bug (correction on this welcomed). The problem is that the "expr" argument to curve() must be an actual expression, not a call to parse that evaluates to an expression. If you look at the code of curve() you'll see why (substitute() does not evaluate expr in the code). Another simple workaround other than sticking in the eval() call is this: myf <- function(x)NUL body(myf)<- parse(text = "{1+x^2}") ## note the additional "{ }" for safety, though not necessary here ## this idiom will continue to work for any text. curve(myf, from = 0, to = 10) ## myf is now the name of a function that executes the parsed text. *** I would appreciate any wiser R programmers correcting any misunderstanding or error in my explanation *** Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, May 2, 2018 at 8:11 PM, Sebastien Bihorel wrote: > > Hi, > > Down a cascade of function calls, I want to use the curve function with an > expression that is a variable. For various reason, this variable must be a > character object and cannot be an expression as required by the curve > function. How do I convert my variable into a expression that is accepted by > curve? > > Thanks in advance for your help. > > ## The following attempts do not work > > myf <- '1+x^2' > curve(myf, from = 0, to = 10) # obviously ! > curve(parse(text=myf), from = 0, to = 10) # not sure why this does not work > > ## This works but does not feel elegant: > eval(parse(text=sprintf('curve(%s, from = 0, to = 10)', myf))) > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Converting a list to a data frame
This is very nice to learn about, Denis, but it seems only fair to point out that the result of rbindlist is not a data frame. You can convert it to a data frame easily, but the copy and indexing semantics of data tables are quite different than data tables, which could be a real headache for someone not prepared for those differences. (To learn more, read the data tables vignette.) Tibbles (as produced by unnest in my previous response) are not data tables either, but they behave much more like data frames than data tables do. On May 2, 2018 1:30:37 PM MDT, "Tóth Dénes" wrote: > > >On 05/02/2018 07:11 PM, Kevin E. Thorpe wrote: >> I suspect this is pretty easy, but I'm having trouble figuring it >out. >> Basically, I have a list of data frames such as the following >example: >> >> list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) >> >> I would like to turn this into data frame where the list elements >are >> essentially rbind'ed together and the element name becomes a new >> variable. For example, I would like to turn the list above into a >data >> frame that looks like this: >> >> data.frame(type=c("A","A","B","B"),x=c(1:2,5:6),y=c(3:4,7:8)) >> >> Appreciate any pointers. > >Hi Kevin, > >data.table::rbindlist does exactly what you want in a very efficient >way: > >library(data.table) >dat <- list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) >rbindlist(dat, idcol = "type") > >Regards, >Denes > > >> >> Kevin >> > >__ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. -- Sent from my phone. Please excuse my brevity. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Calling the curve function with a character object converted into an expression
Typo: should be NULL not NUL of course An alternative approach closer to your original attempt is to use do.call() to explicitly evaluate the expr argument: w <- "1 + x^2" do.call(curve, list(expr = parse(text = w), ylab ="y")) Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, May 2, 2018 at 10:35 PM, Bert Gunter wrote: > Sebastian: > > This is somewhat arcane, perhaps even a bug (correction on this > welcomed). The problem is that the "expr" argument to curve() must be > an actual expression, not a call to parse that evaluates to an > expression. If you look at the code of curve() you'll see why > (substitute() does not evaluate expr in the code). Another simple > workaround other than sticking in the eval() call is this: > > myf <- function(x)NUL > body(myf)<- parse(text = "{1+x^2}") ## note the additional "{ }" > for safety, though not necessary here > ## this idiom will continue to work for any text. > > curve(myf, from = 0, to = 10) ## myf is now the name of a function > that executes the parsed text. > > *** I would appreciate any wiser R programmers correcting any > misunderstanding or error in my explanation *** > > Cheers, > Bert > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Wed, May 2, 2018 at 8:11 PM, Sebastien Bihorel > wrote: >> >> Hi, >> >> Down a cascade of function calls, I want to use the curve function with an >> expression that is a variable. For various reason, this variable must be a >> character object and cannot be an expression as required by the curve >> function. How do I convert my variable into a expression that is accepted by >> curve? >> >> Thanks in advance for your help. >> >> ## The following attempts do not work >> >> myf <- '1+x^2' >> curve(myf, from = 0, to = 10) # obviously ! >> curve(parse(text=myf), from = 0, to = 10) # not sure why this does not work >> >> ## This works but does not feel elegant: >> eval(parse(text=sprintf('curve(%s, from = 0, to = 10)', myf))) >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.