Re: [R] Calling the curve function with a character object converted into an expression

2018-05-02 Thread Bert Gunter
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

Re: [R] Converting a list to a data frame

2018-05-02 Thread Jeff Newmiller
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 s

Re: [R] Calling the curve function with a character object converted into an expression

2018-05-02 Thread Bert Gunter
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 evalu

[R] The stages of standard function evaluation

2018-05-02 Thread Andrew Hoerner
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

[R] Calling the curve function with a character object converted into an expression

2018-05-02 Thread Sebastien Bihorel
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 accep

Re: [R] Converting a list to a data frame

2018-05-02 Thread David L Carlson
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:

Re: [R] using apply

2018-05-02 Thread David L Carlson
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. =

Re: [R] Converting a list to a data frame

2018-05-02 Thread David L Carlson
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 Univer

Re: [R] using apply

2018-05-02 Thread Ulrik Stervbo
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 the

Re: [R] Converting a list to a data frame

2018-05-02 Thread Tóth Dénes
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 w

[R] using apply

2018-05-02 Thread Neha Aggarwal
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 ta

Re: [R] Converting a list to a data frame

2018-05-02 Thread Jeff Newmiller
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

Re: [R] Converting a list to a data frame

2018-05-02 Thread Eivind K. Dovik
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

Re: [R] Converting a list to a data frame

2018-05-02 Thread William Dunlap via R-help
> 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.co

Re: [R] Converting a list to a data frame

2018-05-02 Thread Huzefa Khalil
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,

[R] Converting a list to a data frame

2018-05-02 Thread Kevin E. Thorpe
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 t

Re: [R] Merging dataframes

2018-05-02 Thread Thierry Onkelinx
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,

Re: [R] Merging dataframes

2018-05-02 Thread 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_

Re: [R] Merging dataframes

2018-05-02 Thread Chintanu
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

Re: [R] How would I color points conditional on their value in a plot of a time series

2018-05-02 Thread Martin Maechler
> 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: usin