Re: [R] as.data.frame doesn't set col.names

2017-10-25 Thread Eric Berger
Hi Peter, Thanks for contributing such a great answer. Can you please provide a pointer to the documentation where it explains why dd$B <- s and dd["B"] <- s have such different behavior? (I am perfectly happy if you write the explanation but if it saves you time to point to some reference that wo

Re: [R] R encountered a fatal error. The session was terminated. + *** caught illegal operation ***

2017-10-26 Thread Eric Berger
How about going back to earlier versions if you don't need the latest ones? On Thu, Oct 26, 2017 at 12:59 PM, Klaus Michael Keller < klaus.kel...@graduateinstitute.ch> wrote: > Dear all, > > I just installed the "Short Summer" R update last week. Now, my R Studio > doesn't open anymore! > > -->

Re: [R] My function and NA Values Problem

2017-10-27 Thread Eric Berger
na.rm=TRUE (you need to capitalize) On Fri, Oct 27, 2017 at 10:43 AM, Engin YILMAZ wrote: > Dear R Staff > > My working file is in the annex. "g1.csv" > I have only 2 columns. Rice and coke. > I try to execute following(below) function, but do not work. > Because "Coke" value has NA values. >

Re: [R] Count non-zero values in excluding NA Values

2017-10-29 Thread Eric Berger
If one does not need all the intermediate results then after defining data just one line: grand_total <- nrow(data)*ncol(data) - sum( sapply(data, function(x) sum( is.na(x) | x == 0 ) ) ) # 76 On Sun, Oct 29, 2017 at 2:38 PM, Rui Barradas wrote: > Hello, > > Your attachment didn't came throu

Re: [R] Pass Parameters to RScript?

2017-10-30 Thread Eric Berger
I did a simple search and got hits immediately, e.g. https://www.r-bloggers.com/passing-arguments-to-an-r-script-from-command-lines/ On Mon, Oct 30, 2017 at 2:30 PM, Morkus via R-help wrote: > Is it possible to pass parameters to an R Script, say, from Java or other > language? > > I did some

Re: [R] Pass Parameters to RScript?

2017-10-30 Thread Eric Berger
I do not program in Java but it seems a Java program can make system calls which would be equivalent to running from the command line, but done from within a Java program. Not sure whether that would meet your needs and if not why not. Just a suggestion. Check out http://www.java-samples.com/show

Re: [R] convertTime package.

2017-10-31 Thread Eric Berger
If you need a function (e.g. convertTime ) from a package (unknown?) then you cannot simply instruct R to install the function. e.g. if you give the command > install.packages("convertTime") you will get an error message like "package 'convertTime' is not available (for R version 3.4.1)" I did a G

Re: [R] beta binomial distribution installation

2017-11-01 Thread Eric Berger
Hi, I did a quick search for other packages that provide the beta binomial distribution and found "rmutil". > install.packages("rmutil") The package has the CDF (pbetabinom) and inverse CDF (qbetabinom) among other functions. HTH, Eric On Wed, Nov 1, 2017 at 7:50 AM, MCGUIRE, Rhydwyn < rm...@

Re: [R] Function to save results

2017-11-01 Thread Eric Berger
Some comments: 1. sink() does not return a value. There is on point to set attr <- sink(...). Just give the command sink("C://etc") 2. to complete the saving to the file you must give a second sink command with no argument: sink() So your code would be (pseudo-code, not actual code) sink( "fi

Re: [R] Function to save results

2017-11-01 Thread Eric Berger
ignaling_submodule3.txt") > > sink("C://Users//Priya//Desktop//Attractor analysis_all > genes//synaptogenesis//attr.txt") > > > sink() > > attr <- getAttractors(net, type="asynchronous") > > > Priya > > > On Wednesday, 1 November 20

Re: [R] beta binomial distribution installation

2017-11-01 Thread Eric Berger
tion > "dbb" > > > > > I am confused because if the package TailRank is already there, why the > pervious code does not work to calculate dbb (x,N,u,v) and I got error? If > I do not have the package, would you please let me know the right commands > I should writ

Re: [R] Correct subsetting in R

2017-11-01 Thread Eric Berger
matches <- merge(training,data,by=intersect(names(training),names(data))) HTH, Eric On Wed, Nov 1, 2017 at 6:13 PM, Elahe chalabi via R-help < r-help@r-project.org> wrote: > Hi all, > I have two data frames that one of them does not have the column ID: > > > str(data) > 'data.frame':

Re: [R] Function to save results

2017-11-01 Thread Eric Berger
> output with File | Save to File. > > --- > David L Carlson > Department of Anthropology > Texas A&M University > College Station, TX 77843-4352 > > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Be

Re: [R] Correct subsetting in R

2017-11-01 Thread Eric Berger
frame > > > On Wednesday, November 1, 2017 10:18 AM, Eric Berger < > ericjber...@gmail.com> wrote: > > > > matches <- merge(training,data,by=intersect(names(training),names(data))) > > HTH, > Eric > > > > On Wed, Nov 1, 2017 at 6:13 PM, Elahe chal

Re: [R] Adding Records to a Table in R

2017-11-01 Thread Eric Berger
Hi Paul, #First I set up some sample data since I don't have a copy of your data dtOrig <- as.Date( c("1985-04-01","1985-07-01","1985-12-01","1986-04-01")) dfOrig <- data.frame( TransitDate=dtOrig, Transits=c(100,100,500,325), CargoTons=c(1000,1080,3785,4200) ) #Generate the complete set of dates

Re: [R] FW: Time Series

2017-11-07 Thread Eric Berger
Following Erin's pointer: library(zoo) times <- seq(from=as.POSIXct("2015-12-18 00:00:00"), to=as.POSIXct("2017-10-24 23:00:00"), by="hour") mydata <- rnorm(length(times)) tseri <- zoo( x=mydata, order.by=times ) HTH, Eric On Tue, Nov 7, 2017 at 9:59 AM, Erin Hodgess wrote: > Hello!

[R] Fwd: FW: Time Series

2017-11-07 Thread Eric Berger
a, order.by=times ) when use it without x=mydata like, tseri <- zoo( x, order.by=times ) it works. I checked it by following command x[times==as.POSIXct("2015-12-18 02:00:00")] and it gave me the true value. Do you think it is okay? By the way, I appreciate for fast rep

Re: [R] Fitdistrplus and Custom Probability Density

2017-11-07 Thread Eric Berger
Why not define your own functions based on d? e.g. myCumDist <- function(x) { integrate(d, lower=-Inf, upper=x)$value } myQuantile <- function(x) { uniroot(f=function(y) { h(y) - x }, interval=c(-5,5)) } # limits -5,5 should be replaced by your own which might require some fiddling e.g. d <- fun

Re: [R] Ggplot error

2017-11-08 Thread Eric Berger
I was not able to reproduce this problem. I tried two environments 1. Ubuntu 14.04.5 LTS, R version 3.4.2 (same R version as yours) 2. Windows 10, same R version On Wed, Nov 8, 2017 at 9:50 AM, Zeki ÇATAV wrote: > Hello, > I've an error recently. > > ggplot(data = mtcars, aes(x= wt, y= mpg)) +

Re: [R] Adding Records to a Table in R

2017-11-08 Thread Eric Berger
gt; > > -Original Message- > > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul > Bernal > > Sent: Wednesday, November 8, 2017 2:46 PM > > To: Eric Berger > > Cc: r-help@r-project.org > > Subject: Re: [R] Adding Records to

Re: [R] Calculating frequencies of multiple values in 200 colomns

2017-11-10 Thread Eric Berger
How about this workaround - add 1 to the vector x <- c(1,0,2,1,0,2,2,0,2,1) tabulate(x) # [1] 3 4 tabulate(x+1) #[1] 3 3 4 On Fri, Nov 10, 2017 at 4:34 PM, Marc Schwartz wrote: > Hi, > > To clarify the default behavior that Boris is referencing below, note the > definition of the 'bin' argument

Re: [R] effects package x axis labels

2017-11-11 Thread Eric Berger
Hi Andras, I have not used this package before but I did the following steps to arrive at an answer. Hopefully both the answer is what you are looking for and also the steps to understand how you can answer such questions yourself in the future. 1. R is an object-oriented language, but there are se

Re: [R] R6 object that is a list of referenced object

2017-11-16 Thread Eric Berger
Hi Cristina, You can try this: > Community <- R6Class("Community", public = list( e = NULL, initialize = function() { self$e <- list() }, add = function( person ) { self$e[[ length(self$e) + 1]] <<- p

Re: [R] Risks of using "function <- package::function" ?

2017-11-17 Thread Eric Berger
As Jeff recommends, I use the pkg::fun for clarity. However I probably use it more than needed (e.g. I use the dplyr:: prefix on all dplyr function calls instead of just the functions with name collisions). Are there any tools that can be used (like a form of lint) to identify uses of functions wit

Re: [R] Do I need to transform backtest returns before using pbo (probability of backtest overfitting) package functions?

2017-11-21 Thread Eric Berger
Hi Joe, The centering and re-scaling is done for the purposes of his example, and also to be consistent with his definition of the sharpe function. In particular, note that the sharpe function has the rf (riskfree) parameter with a default value of .03/252 i.e. an ANNUAL 3% rate converted to a DAIL

Re: [R] Do I need to transform backtest returns before using pbo (probability of backtest overfitting) package functions?

2017-11-21 Thread Eric Berger
that each column has mean MU_D and std deviation SIGMA_D. HTH, Eric On Tue, Nov 21, 2017 at 2:33 PM, Eric Berger wrote: > Hi Joe, > The centering and re-scaling is done for the purposes of his example, and > also to be consistent with his definition of the sharpe function. > I

Re: [R] Do I need to transform backtest returns before using pbo (probability of backtest overfitting) package functions?

2017-11-21 Thread Eric Berger
to have > whatever properties they have (meaning they will have whatever average and > std dev they happen to have). Is that correct? > > Thanks, -Joe > > >> On Tue, Nov 21, 2017 at 5:36 AM, Eric Berger wrote: >> [re-sending - previous email went out by accident be

Re: [R] Scatterplot of many variables against a single variable

2017-11-27 Thread Eric Berger
LOL. Great reply Jim. (N.B. Jim's conclusion is "debatable" by a judicious choice of seed. e.g. set.seed(79) suggests that making the request more readable will actually lower the number of useful answers. :-)) On Mon, Nov 27, 2017 at 11:42 AM, Jim Lemon wrote: > Hi Engin, > Sadly, your illustr

Re: [R] DeSolve Package and Moving Average

2017-11-29 Thread Eric Berger
Since you only provide pseudo-code I will give a guess as to the source of the problem. It is easy to get "burned" by use of the ifelse statement. Its results have the same "shape" as the first argument. My suggestion is to try replacing ifelse by a standard if ( ) { } else { } HTH, Eric

Re: [R] source files in temp environment

2017-12-02 Thread Eric Berger
I totally agree with Duncan's last point. I find it hard to reconcile your early remarks (which indicate a deep knowledge of programming) with the idea that your code is not built up from combining small(ish) functions. Small functions would generally be considered best practices. Try searching on

Re: [R] Rcpp, dyn.load and C++ problems

2017-12-02 Thread Eric Berger
.Call("compute_values_cpp") Also, if you were passing arguments to the C++ function you would need to declare the function differently. Do a search on "Rcpp calling C++ functions from R" HTH, Eric On Sun, Dec 3, 2017 at 3:06 AM, Martin Møller Skarbiniks Pedersen < traxpla...@gmail.com> wrote: >

Re: [R] problem with the behaviour of dashed lines in R plots

2017-12-04 Thread Eric Berger
Hi, Sarah's last comment about using min/max x got me thinking. It's not that the points are "very close together", it's that the x-values are not ordered. So the plot is actually drawing a dashed line back-and-forth between different points on the line, which has the effect of making the result ap

Re: [R] Curiously short cycles in iterated permutations with the same seed

2017-12-07 Thread Eric Berger
Hi Boris, Do a search on "the order of elements of the symmetric group". (This search will also turn up homework questions and solutions.) You will understand why you are seeing this once you understand how a permutation is decomposed into cycles and how the order relates to a partition of n (n=10

Re: [R] difference between ifelse and if...else?

2017-12-13 Thread Eric Berger
ifelse returns the "shape" of the first argument In your ifelse the shape of "3 > 2" is a vector of length one, so it will return a vector length one. Avoid "ifelse" until you are very comfortable with it. It can often burn you. On Wed, Dec 13, 2017 at 5:33 PM, jeremiah rounds wrote: > ifel

Re: [R] help with recursive function

2017-12-14 Thread Eric Berger
You seem to have a typo at this expression (and some others like it) Namely, you write any(!dat2$norm_sd) >= 1 when you possibly meant to write !( any(dat2$norm_sd) >= 1 ) i.e. I think your ! seems to be in the wrong place. HTH, Eric On Thu, Dec 14, 2017 at 3:26 PM, DIGHE, NILESH [AG/2362]

Re: [R] help with recursive function

2017-12-14 Thread Eric Berger
My own typo ... whoops ... !( any(dat2$norm_sd >= 1 )) On Thu, Dec 14, 2017 at 3:43 PM, Eric Berger wrote: > You seem to have a typo at this expression (and some others like it) > > Namely, you write > > any(!dat2$norm_sd) >= 1 > > when you possibly meant to wr

Re: [R] help with recursive function

2017-12-14 Thread Eric Berger
gt; return(df1) > > } > >else { > > df2 <- recursive_funlp() > > return(df2) > > } > > } > > df3 <- recursive_funlp(dataset = dat1, func = funlp2) > > df3 > > } >

Re: [R] help with recursive function

2017-12-14 Thread Eric Berger
2017 at 5:33 PM, Eric Berger wrote: > The message is coming from your stopifnot() condition being met. > > > On Thu, Dec 14, 2017 at 5:31 PM, DIGHE, NILESH [AG/2362] < > nilesh.di...@monsanto.com> wrote: > >> Hi, I accidently left out few lines of code from the calclp

Re: [R] Finding center of mass in a hydrologic time series

2017-12-16 Thread Eric Berger
Hi Eric, How about match( TRUE, cumsum(hyd/sum(hyd)) > .5 ) - 1 HTH, Eric On Sat, Dec 16, 2017 at 3:18 PM, Morway, Eric wrote: > The small bit of script below is an example of what I'm attempting to do - > find the day on which the 'center of mass' occurs. In case that is the > wrong term, I

Re: [R] Auto Data in the ISLR Package

2017-12-17 Thread Eric Berger
myAuto <- Auto[ grep("ford|toyota",Auto$name),] On Sat, Dec 16, 2017 at 10:28 PM, Bert Gunter wrote: > I did not care to load the packages -- small reproducible examples are > preferable, as the posting guide suggests. > > But, if I have understood correctly: > > See, e.g. ?subset > > Alternat

Re: [R] Auto Data in the ISLR Package

2017-12-17 Thread Eric Berger
eter dalgaard wrote: > That probably works in this case, but it would cause grief if another car > make had "ford" somewhere inside its name e.g. "bedford". Safer general > practice is > > Auto[Auto$name %in% c("ford", "toyota"),] > > or

Re: [R] Auto Data in the ISLR Package

2017-12-17 Thread Eric Berger
gain thank you all. > > abou > > __ > > > *AbouEl-Makarim Aboueissa, PhD* > > *Professor of Statistics* > > *Department of Mathematics and Statistics* > *University of Southern Maine* > > > On Sun, Dec 17, 2017 at 3:10 AM, Eric Berger &g

Re: [R] Finding center of mass in a hydrologic time series

2017-12-18 Thread Eric Berger
/maps.google.com/?q=2730+N.+Deer+Run+Rd.Carson+City,+NV+89701+(775&entry=gmail&source=g> > Carson City, NV 89701 > <https://maps.google.com/?q=2730+N.+Deer+Run+Rd.Carson+City,+NV+89701+(775&entry=gmail&source=g> > (775 > <https://maps.google.com/?q=2730+N.+Deer+R

Re: [R] Help with script

2017-12-28 Thread Eric Berger
Hi Pablo, There are probably many ways to do this in R. This suggestion uses dplyr. The solution is actually only one line (see the line starting with dat2). The first section simply creates the example data. library(dplyr) # 1. set up the example data m <- matrix( c(0,0,0,0,0,1,1,1,0,0,1,1,1,1,2,

Re: [R] Writing text files out of a dataset

2017-12-29 Thread Eric Berger
You have an error with the filename in the loop. Try replacing the relevant line wtih fileConn<-file(sprintf("TESTI/%d.txt",i)) HTH, Eric On Fri, Dec 29, 2017 at 4:31 PM, Luca Meyer wrote: > Hello, > > I am trying to run the following syntax for all cases within the dataframe > "data" > > d1 <

Re: [R] Discrete valued time series data sets.

2018-01-02 Thread Eric Berger
Hi Rolf, I looked at https://docs.microsoft.com/en-us/azure/sql-database/sql-database-public-data-sets One of the first sets in the list is the airline time series (I think it is also used in dplyr examples). https://www.transtats.bts.gov/OT_Delay/OT_DelayCause1.asp You might find other possibil

Re: [R] Replace NAs in split lists

2018-01-08 Thread Eric Berger
You can enforce these assumptions by sorting on multiple columns, which leads to na.locf(df1[ order(df1$ID,df1$Value), ]) On Mon, Jan 8, 2018 at 4:19 PM, Jeff Newmiller wrote: > Yes, you are right if the IDs are always sequentially-adjacent and the > first non-NA value appears in the first re

Re: [R] application of R

2018-01-11 Thread Eric Berger
Marc and Jeff give excellent advice. Since you have a commercial perspective, here are two more points to consider: 1. There are companies that sell software built on R. For example, the company Rstudio.com develops both free and "professional" versions of its products RStudio and Shiny. 2. You ask

Re: [R] barplot that displays sums of values of 2 y colums grouped by different variables

2018-01-15 Thread Eric Berger
'position="dodge"' has no effect in the plot because the x-axis is a factor variable. The bars do not need to be moved to avoid each other. The 'aes(fill=y)' is specifying that you want the color gradient to capture the sums in the 'y' variable. You might be better off to use 'no' and 'yes' rather

Re: [R] barplot that displays sums of values of 2 y colums grouped by different variables

2018-01-15 Thread Eric Berger
for "yes" , the other, beside > it, with the sum for "no". > > I am way off track with my method here? > > Thanks, > Ken > > Sent from Blue <http://www.bluemail.me/r?b=11745> > On Jan 15, 2018, at 14:34, Eric Berger wrote: >> >> 'p

Re: [R] Steps to create spatial plots

2018-01-15 Thread Eric Berger
If layer$z is a matrix and you want to reverse the order of the rows, you can do: n <- nrow(layer$z) layer$z <- layer$z[ n:1, ] HTH, Eric On Tue, Jan 16, 2018 at 8:43 AM, lily li wrote: > Sorry for the emails, I just wanted to have an example. > layer$z > > 1 1 3 4 6 2 > 2 3 4 1 2 9

[R] Split charts with ggplot2, tidyquant

2018-01-17 Thread Eric Berger
A very common chart in the financial markets is a split chart with two time series shown in two vertically stacked sub-charts. A classic case would be the top panel showing the time series of historical prices of some stock, and the bottom panel showing the volume traded per day immediately below i

Re: [R] roxygen2 error - x$tag operator is invalid for atomic vectors

2018-01-17 Thread Eric Berger
This is an error message from R. For example, if you give the following R commands > a <- 5 > a$foo This will generate the error message: Error in a$foo : $ operator is invalid for atomic vectors So you can search for the string 'x$tag' in your code (or possibly in the package). HTH, Eric On W

Re: [R] reading lisp file in R

2018-01-17 Thread Eric Berger
It seems the file contains records, with each record having 18 fields. I would use awk (standard unix tool), creating an awk script to process the file into a new file with one line for each record, each line with 18 fields, say comma-separated. The csv file can then be easily read into R via the f

Re: [R] Split charts with ggplot2, tidyquant

2018-01-18 Thread Eric Berger
Hi Charlie, I am comfortable to put the data in any way that works best. Here are two possibilities: an xts and a data frame. library(quantmod) quantmod::getSymbols("SPY") # creates xts variable SPY SPYxts <- SPY[,c("SPY.Close","SPY.Volume")] SPYdf <- data.frame(Date=index(SPYxts),close=as.numer

Re: [R] Split charts with ggplot2, tidyquant

2018-01-19 Thread Eric Berger
e ggplot2 code: > > library(ggplot2) > ggplot(plotDF, aes(x=Date, y=resp)) + > facet_wrap(~parameter, ncol=1, scales="free") + > geom_line() > > > Hope that does the trick! > > Charlie > > > > On 01/18/2018 02:11 PM, Eric Berger wrote: > >

Re: [R] Split charts with ggplot2, tidyquant

2018-01-21 Thread Eric Berger
t; comic strip ) >> >> On Sat, Jan 20, 2018 at 12:19 PM, Charlie Redmon > <mailto:redm...@gmail.com>> wrote: >> >> For this kind of control you will probably need to move to base >> graphics >> and utilize the `fig` argument in par(), in whi

Re: [R] Newbie - Scrape Data From PDFs?

2018-01-23 Thread Eric Berger
Hi Scott, I have never done this myself but I read something recently on the r-help distribution that was related. I just did a quick search and found a few hits that might work for you. 1. https://medium.com/@CharlesBordet/how-to-extract-and-clean-data-from-pdf-files-in-r-da11964e252e 2. http://

Re: [R] Newbie wants to compare 2 huge RDSs row by row.

2018-01-26 Thread Eric Berger
Hi Marsh, An RDS is not a data structure such as a data.frame. It can be anything. For example if I want to save my objects a, b, c I could do: > saveRDS( list(a,b,c,), file="tmp.RDS") Then read them back later with > myList <- readRDS( "tmp.RDS" ) Do you have additional information about your "RD

Re: [R] Newbie wants to compare 2 huge RDSs row by row.

2018-01-28 Thread Eric Berger
; > Ulrik > > > > Marsh Hardy ARA/RISK schrieb am So., 28. Jan. 2018, > 04:14: > > > >> Cool, looks like that'd do it, almost as if converting an entire record > to > >> a character string and comparing strings. > >> > >> ___

Re: [R] Result show the values of fitting gamma parameter

2018-01-29 Thread Eric Berger
Capture the results of the apply command into an object and then work with that. Here is one way to do it: > res <- apply(C, 2, fitdist, "gamma") > out <- c( res$A$estimate["shape"], res$B$estimate["shape"], res$A$estimate["rate"], res$B$estimate["rate"]) > names(out) <- c("A shape","B shape","A r

Re: [R] Simulation based on runif to get mean

2018-01-30 Thread Eric Berger
Or a shorter version of Rui's approach: set.seed(2511)# Make the results reproducible fun <- function(n){ f <- function(){ c(mean(runif(5,1,10)),mean(runif(5,10,20))) } replicate(n, f()) } fun(10) On Tue, Jan 30, 2018 at 12:03 PM, Rui Barradas wrote: > Hello, > > Another way would

Re: [R] Calculating angle of a polyline

2018-01-30 Thread Eric Berger
Assuming your polyline is defined by two vectors, one for the x coordinates, one for the y coordinates, you can try the following library(NISTunits) polyangles <- function(xV,yV) { stopifnot( (length(xV)==length(yV)) && (length(xV) >= 3)) v <- function(i) { c( xV[i]-xV[i-1], yV[i]-yV[i-1])}

Re: [R] Calculating angle of a polyline

2018-01-30 Thread Eric Berger
re = xV, im = yV) > c(NA, diff(Arg(diff(z))), NA) # radians, positive is counter-clockwise > } > > x <- c(0:3) > > y <- c(0,0,1,1) > > polyAngles2(x,y) / pi * 180 > [1] NA 45 -45 NA > > > > Bill Dunlap > TIBCO Software > wdunlap tibco.com

Re: [R] copy/paste of large amount of code to terminal leads to scrambled/missing characters

2018-02-03 Thread Eric Berger
Hi Martin, Why not just do the following? In your editor after you create the script save it to a file, say "foo.R". Then in your R session you give the command > source("foo.R") HTH, Eric On Sun, Feb 4, 2018 at 6:33 AM, Bert Gunter wrote: > Obvious suggestion: use a more capable IDE instead o

Re: [R] TreeBUGS - subscript out of bounds

2018-02-21 Thread Eric Berger
Hi Max, Here's an example that will generate that error. Maybe it will point you to your problem. # create a 2x2 matrix > m <- matrix(1:4,nrow=2) # refer to column 3 - which does not exist > m[,3] # Error in m[, 3] : subscript out of bounds HTH, Eric On Wed, Feb 21, 2018 at 4:35 PM, Max Hen

Re: [R] alternative for multiple if_else statements

2018-02-22 Thread Eric Berger
Hi, 1. I think the reason that the different ordering leads to different results is because of the following: date[ some condition is true ][1] will give you an NA if there are no rows where 'some condition holds'. In the code that 'works' you don't have such a situation, but in the cod

Re: [R] alternative for multiple if_else statements

2018-02-22 Thread Eric Berger
_1"][1]] <- "survey_2013" > > > > #filter trialData > > trialData <- trialData %>% filter(id == "id_786/3") > > > > *#attempt 2 works: code for survey* > > trialData$survey_year[trialData$date >= trialData$date[trialData$surve

Re: [R] reshaping column items into rows per unique ID

2018-02-25 Thread Eric Berger
Hi Allaisone, I took a slightly different approach but you might find this either as or more useful than your approach, or at least a start on the path to a solution you need. df1 <- data.frame(CustId=c(1,1,1,2,3,3,4,4,4),DietType=c("a","c","b","f","a","j","c","c","f"), strin

Re: [R] Repeated use of dyn.load().

2018-03-01 Thread Eric Berger
Good question Rolf. Rui, thanks for pointing out dyn.unload. When I started using Rcpp a couple of years ago I got burned by stale .so enough times that I adopted a policy of recompile-then-start new R session. My workflow does not include Rolf's "brazillion" repeats, so the overhead of this approa

Re: [R] Variable centring within "predict.coxph"

2018-03-02 Thread Eric Berger
Hi Laura, I will state up front that I have no experience or knowledge of the Cox model or the survival package. Out of curiosity I loaded the package and did ?coxph and found the following comment in the documentation: "The routine internally scales and centers data to avoid overflow in the argum

Re: [R] lmrob gives NA coefficients

2018-03-04 Thread Eric Berger
What is 'd'? What is 'n'? On Sun, Mar 4, 2018 at 12:14 PM, Christien Kerbert < christienkerb...@gmail.com> wrote: > Thanks for your reply. > > I use mvrnorm from the *MASS* package and lmrob from the *robustbase* > package. > > To further explain my data generating process, the idea is as follow

Re: [R] lmrob gives NA coefficients

2018-03-04 Thread Eric Berger
Hard to help you if you don't provide a reproducible example. On Sun, Mar 4, 2018 at 1:05 PM, Christien Kerbert < christienkerb...@gmail.com> wrote: > d is the number of observed variables (d = 3 in this example). n is the > number of observations. > > 2018-03-04 11:3

Re: [R] Change Function based on ifelse() condtion

2018-03-04 Thread Eric Berger
Hi Christofer, You cannot assign to list(...). You can do the following myList <- list(...)[!names(list(...)) %in% 'mc.cores'] HTH, Eric On Sun, Mar 4, 2018 at 6:38 PM, Christofer Bogaso < bogaso.christo...@gmail.com> wrote: > Hi, > > As an example, I want to create below kind of custom Functio

Re: [R] Change Function based on ifelse() condtion

2018-03-04 Thread Eric Berger
ic - with this approach I am getting below error : > > Error in FUN(X[[i]], ...) : unused argument (list()) > > On Sun, Mar 4, 2018 at 10:18 PM, Eric Berger > wrote: > > Hi Christofer, > > You cannot assign to list(...). You can do the following > > > > myLi

Re: [R] Change Function based on ifelse() condtion

2018-03-04 Thread Eric Berger
#x27;mc.cores'] > } > return(lapply(X, FUN, myList)) > } > } > > Here, I am not passing ... anymore rather passing myList > > On Sun, Mar 4, 2018 at 10:37 PM, Eric Berger > wrote: > > Hi Christofer, > > Before you made the change that I suggested, your program was

Re: [R] Change Function based on ifelse() condtion

2018-03-04 Thread Eric Berger
> Error message : > > Error in FUN(X[[i]], ...) : unused argument (list()) > > Kindly note that, with Apply_MC = TRUE, it is working perfectly. > > On Sun, Mar 4, 2018 at 10:45 PM, Eric Berger > wrote: > > That's fine. The issue is how you called Lapply_me(). Wha

Re: [R] add single points to a level plot

2018-03-08 Thread Eric Berger
You need to load the package 'rasterVis' > library(rasterVis) HTH, Eric On Thu, Mar 8, 2018 at 5:11 PM, lily li wrote: > Hi all, > > I ran the code: > > s <- stack(replicate(2, raster(matrix(runif(100), 10 > > xy <- data.frame(coordinates(sampleRandom(s, 10, sp=TRUE)), > +

Re: [R] Learning advanced R

2018-03-14 Thread Eric Berger
Bert's suggestion is good as a pointer to a variety of resources. Sticking to the book format there are two of Hadley Wickham's books, which have the advantage that they are freely available. You can either read them online or download the source from github and create your own copy (which you can

Re: [R] the same function returning different values when called differently..

2018-03-14 Thread Eric Berger
Hi Akshay, Presumably PFC.NS and snl[[159]] are not exactly the same. You can start by trying to determine if (and then how) they differ. e.g. > identical(PFC.NS, snl[[159]]) presumably this will result in FALSE then compare > class(PFC.NS) > class(snl[[159]]) etc HTH, Eric On Wed, Mar 14, 201

[R] R crashing with a segmentation fault: how to locate the cause

2018-03-14 Thread Eric Berger
I have a littler script which is crashing with a segmentation fault. I tried to find out why by running it through valgrind, which produced the output below. I am not sure how to proceed from here (other than binary search with print statements). Any help would be appreciated. Thanks, Eric ==1258

[R] Fwd: the same function returning different values when called differently..

2018-03-14 Thread Eric Berger
...how do I effect it? create a list with some other element list... for example snl[[200]] == PFC.NS? very many thanks for your time and effort... yours sincerely, AKSHAY M KULKARNI ------ *From:* Eric Berger *Sent:* Wednesday, March 14, 2018 5:22 PM *To:* akshay

[R] Fwd: Learning advanced R

2018-03-14 Thread Eric Berger
uired, but the script does not run. Is there an additional script required? Best, Albrecht -- Albrecht Kauffmann alkau...@fastmail.fm Am Mi, 14. Mär 2018, um 09:13, schrieb Eric Berger: > Bert's suggestion is good as a pointer to a variety of resources. > Sticking to the book fo

Re: [R] stats 'dist' euclidean distance calculation

2018-03-15 Thread Eric Berger
Hi Cheyenne, I noticed one thing that might be helpful to you. First, I took a shortcut to the case of interest: > m <- matrix(c(2,1,1,0,1,1,NA,1,1,NA,1,1,2,1,2,0,1,0),nrow=3) > colnames(m) <- c("1.G","1.A","2.C","2.A","3.G","3.A") > m # 1.G 1.A 2.C 2.A 3.G 3.A # [1,] 20 NA

Re: [R] Creating the right table from lapply list

2018-03-29 Thread Eric Berger
I like Don's answer which is clean and clear. A frequently useful alternative to lapply() is sapply(). Taking the sapply() route also avoids the need for do.call(). So a modified version of Don's code would be: ## example data output <- list(1:5, 1:7, 1:4) maxlen <- max( sapply(output, length) )

Re: [R] convert numeric variables to factor

2018-04-10 Thread Eric Berger
You are missing a comma between "MARITAL" and "JOBSTATUS". On Tue, Apr 10, 2018 at 10:27 AM, Saif Tauheed wrote: > I run this command for converting the numerical variable into factor. > However, I get the following error message. > > > cols<- c(“GrMM", "RELG", "CASTE1", "SECTOR", "SECTOR4","AGE

Re: [R] Understanding which

2018-04-18 Thread Eric Berger
Here's a hint: > y <- which(x>100) > identical(y,y) # TRUE > identical(y,-y) # TRUE The '-' is misleading - it is absorbed into the empty y, leaving the request x[y] to be x for an empty set of indices. HTH, Eric On Wed, Apr 18, 2018 at 2:13 PM, Ashim Kapoor wrote: > Dear All, > > Here is a

Re: [R] Check if row of dataframe is superset of any row in another dataframe.

2018-04-21 Thread Eric Berger
Hi Neha, How about this? A <- as.matrix(A) B <- as.matrix(B) C <- A %*% t(B) SA <- apply(A, MAR=1, sum ) SB <- apply(B, MAR=1, sum ) vapply( 1:nrow(B), function(j) { sum( C[,j]==SA & SA <= SB[j] ) > 0 }, 1 ) HTH, Eric On Sat, Apr 21, 2018 at 10:27 AM, Neha Aggarwal wrote: > Hi, > > I am

Re: [R] How to dynamically add variables to a dataframe

2018-04-22 Thread Eric Berger
Hi Luca, How about this? # create some dummy data since I don't have your d0 or d1 > n <- 3 > d0 <- data.frame(a=runif(5),b=runif(5)) # here's the suggested code > d1 <- cbind(d0, matrix(0,nrow(d0),n)) > colnames(d1)[1:n + ncol(d0)] <- paste("V",1:n,sep="") HTH, Eric On Sun, Apr 22, 2018 at 1

Re: [R] Rolling window difference for zoo time series

2018-04-24 Thread Eric Berger
Zoo_TS/lag(Zoo_TS) - 1 On Tue, Apr 24, 2018 at 9:29 PM, Christofer Bogaso < bogaso.christo...@gmail.com> wrote: > Hi, > > I have a 'zoo' time series as below : > > Zoo_TS = zoo(5:1, as.Date(Sys.time())+0:4) > > Now I want to calculate First order difference of order 1, rolling > window basis i.e

Re: [R] How to define mutualy exclusive parameters of a function

2018-04-26 Thread Eric Berger
Hi Pol, Here is one way: fb <- function(mean=NULL, median=NULL, mode=NULL, a, b=0.95, lower=F) { stopifnot ( (is.null(mean) + is.null(median) + is.null(mode)) == 2 ) etc... } HTH, Eric On Thu, Apr 26, 2018 at 4:46 PM, Polychronis Kostoulas < polychronis.kostou...@gmail.com> wrote:

Re: [R] adding overall constraint in optim()

2018-05-06 Thread Eric Berger
Hi Michael, A few comments 1. To add the constraint sum(wgt.vect=1) you would use the method of Lagrange multipliers. What this means is that in addition to the w_i (the components of the weight variables) you would add an additional variable, call it lambda. Then you would modify your opti

Re: [R] adding overall constraint in optim()

2018-05-06 Thread Eric Berger
typo: lambda * (sum(wgt.wect) - 1) On Sun, May 6, 2018 at 10:51 AM, Eric Berger wrote: > Hi Michael, > A few comments > 1. To add the constraint sum(wgt.vect=1) you would use the method of > Lagrange multipliers. > What this means is that in addition to the w_i (the co

Re: [R] a question about R script : "Can only modify plain character vectors."

2018-05-08 Thread Eric Berger
Can you create a small script that reproduces the problem? If you can, then please post it to the mailing list. On Tue, May 8, 2018 at 4:24 PM, Bogdan Tanasa wrote: > Dear all, > > would appreciate a suggestion about the following situation : I am running > a script in R, and shall i execute it

Re: [R] Adding Year-Month-Day to X axis

2018-05-08 Thread Eric Berger
abline (v=x_mmdd, lty=3, lwd=1.0, col="blue") On Tue, May 8, 2018 at 5:23 PM, Gregory Coats wrote: > Since the horizontal axis side=1 is year-month-day, how do I issue an > abline command to draw dashed vertical lines, as a background grid, within > the graph’s border? Similar to the ablin

Re: [R] help with json data from the web into data frame in R

2018-05-08 Thread Eric Berger
Hi Rich, Take a look at the function fromJSON found in the rjson package. Note that the Usage in the help page: ?fromJSON names the second argument 'file' but if you look at the description the argument can be a URL. HTH, Eric On Tue, May 8, 2018 at 6:16 PM, Evans, Richard K. (GRC-H000) < richar

Re: [R] Average of results coming from B=100 repetitions (looping)

2018-05-08 Thread Eric Berger
mean(unlist(lst)) On Tue, May 8, 2018 at 10:26 PM, varin sacha via R-help < r-help@r-project.org> wrote: > > Dear R-experts, > > Here below the reproducible example. I am trying to get the average of the > 100 results coming from the "lst" function. I have tried lst$mean and > mean(lst). It doe

Re: [R] Seasonal weekly average

2018-05-09 Thread Eric Berger
Hi Shakeel, One approach would be to look at the dplyr package and its functions group_by() and summarise(). These should be useful in preparing the data. (Alternatively if you know SQL you might look at dbplyr.) On the plotting side you can use plot(...) for the first line and then lines(...) for

Re: [R] strange behavior of plotmath

2018-05-21 Thread Eric Berger
FYI I see everything after the '^' as a superscript. The '~' does act as a space. (When I omit it there is less space between the '-' and the '('. On Mon, May 21, 2018 at 3:09 PM, Jinsong Zhao wrote: > hi there, > > I find the following codes produce strange output. > > plot(1:10, xlab = expre

Re: [R] how to make the code more efficient using lapply

2018-05-25 Thread Eric Berger
Hi Stephen, I am not sure that the "for loop" is the source of slowness. You seem to be doing a lot of unnecessary work each time through the loop. e.g. no need to check if it's the last file, just move that section outside of the loop. It will be executed when the loop finishes. As it is you are c

  1   2   3   4   5   6   >