Re: [R] run r script in r-fiddle

2017-10-31 Thread Gabor Grothendieck
Try that source statement here -- it is running R 3.4.1: https://www.tutorialspoint.com/execute_r_online.php On Mon, Oct 30, 2017 at 11:14 AM, Suzen, Mehmet wrote: > Note that, looks like r-fiddle runs R 3.1.2. > > __ > R-help@r-project.org mailing li

Re: [R] Portable R in zip file for Windows

2018-01-25 Thread Gabor Grothendieck
I believe that the ordinary Windows installer for R can produce a portable result by choosing the appropriate configuration options from the offered screens when you run the installer Be sure to enter the desired path in the Select Destination Location screen, choose Yes on the Startup options scr

Re: [R] Portable R in zip file for Windows

2018-01-25 Thread Gabor Grothendieck
but can't execute the exe due to security > restrictions. > Geez, really, treating people who ask questions this way just makes you > don't want to ask a single one. > > > On Thu, Jan 25, 2018, 11:19 Gabor Grothendieck > wrote: >> >> I believe that the ord

Re: [R] Plotting quarterly time series

2018-01-28 Thread Gabor Grothendieck
Using Achim's d this also works to generate z where FUN is a function used to transform the index column and format is also passed to FUN. z <- read.zoo(d, index = "time", FUN = as.yearqtr, format = "Q%q %Y") On Sun, Jan 28, 2018 at 4:53 PM, Achim Zeileis wrote: > On Sun, 28 Jan 2018, p...@phili

Re: [R] Equivalent of gtools::mixedsort in R base

2018-03-12 Thread Gabor Grothendieck
split any mixed columns into letter and number columns and then order can be used on that: DF <- data.frame(x = c("a10", "a2", "a1")) o <- do.call("order", transform(DF, let = gsub("\\d", "", x), no = as.numeric(gsub("\\D", "", x)),

Re: [R] Take average of previous weeks

2018-03-25 Thread Gabor Grothendieck
There is no `value` column in the `dput` output shown in the question so using `tmin` instead note that the `width=` argument of `rollapply` can be a list containing a vector of offsets (-1 is prior value, -2 is value before that, etc.) and that we can use `rollapplyr` with an `r` on the end to ge

Re: [R] Extract function parameters from a R expression

2018-06-20 Thread Gabor Grothendieck
If you specifically want to know which packages were loaded by the script then using a vanilla version of R (i.e. one where only base packages are loaded): vanilla_search <- search() source("myRprg.R") setdiff(search(), vanilla_search) On Wed, Jun 20, 2018 at 4:08 AM, Sigbert Klinke wrot

Re: [R] Combine by columns a vector with another vector that is constant across rows

2018-07-03 Thread Gabor Grothendieck
Try Reduce: Reduce(cbind, vec, 1:5) On Tue, Jul 3, 2018 at 9:28 AM, Viechtbauer, Wolfgang (SP) wrote: > Hi All, > > I have one vector that I want to combine with another vector and that other > vector should be the same for every row in the combined matrix. This > obviously does not work: >

Re: [R] Combine by columns a vector with another vector that is constant across rows

2018-07-03 Thread Gabor Grothendieck
or this variation if you don't want the first column to be named init: Reduce(cbind2, vec, 1:5) On Tue, Jul 3, 2018 at 10:46 AM, Gabor Grothendieck wrote: > Try Reduce: > > Reduce(cbind, vec, 1:5) > > On Tue, Jul 3, 2018 at 9:28 AM, Viechtbauer, Wolfgang (SP) > wr

Re: [R] How to calculate Rolling mean for a List object

2017-05-14 Thread Gabor Grothendieck
Try this code which does not use rollapply: w <- 3 Mean <- function(L) Reduce("+", L) / length(L) lapply(w:length(Data), function(i) Mean(Data[seq(to = i, length = w)])) On Sun, May 14, 2017 at 6:44 PM, Christofer Bogaso wrote: > Hi again, > > I am looking to find a way on how to calculate Rolli

Re: [R] rollapply() produces NAs

2017-05-28 Thread Gabor Grothendieck
Maybe you want this.It computes VaRfun(r[c(i-500, i-1)] for each i for which the argument to r makes sense. rollapply(r, width = list(c(-500, -1)), FUN = VaRfun), On Sat, May 27, 2017 at 5:29 PM, Sepp via R-help wrote: > Hello, > I am fairly new to R and trying to calculate value at risk with ex

Re: [R] Package sqldf in R and dates manipulation

2017-08-11 Thread Gabor Grothendieck
See FAQ #4 on the sqldf github home page. On Fri, Aug 11, 2017 at 9:21 AM, Mangalani Peter Makananisa wrote: > Dear all, > > I recently read the book " R data preperation and manipulation using sqldf > package" by Djoni Darmawikarta > However, I have a problem with manipulation of dates using t

Re: [R] Case statement in sqldf

2017-09-11 Thread Gabor Grothendieck
2018-03-3 in your code should be 2018-03-31. The line then'201415' needs to be fixed. When posting please provide minimal self-contained examples. There was no input provided and library statements not relevant to the posted code were included. Fixing the invalid date and bad line, getting r

Re: [R] Convert data into zoo object using Performance analytics package

2017-09-18 Thread Gabor Grothendieck
Depending on how you created df maybe your code has the column names wrong. In any case these 4 alternatives all work. Start a fresh R session and then copy and paste this into it. library(zoo) u <- "https://faculty.washington.edu/ezivot/econ424/sbuxPrices.csv"; fmt <- "%m/%d/%Y" # 1 sbux1.z <

Re: [R] symbolic computing example with Ryacas

2017-09-19 Thread Gabor Grothendieck
Here are some more examples: library(Ryacas) x <- Sym("x") yacas("x:=2") Eval(x*x) ## [1] 4 # vignette has similar example y <- Sym("y") Eval(Subst(y*y, y, 3)) ## [1] 9 # demo("Ryacas-Function") has similar example to this f <- function(z) {} body(f) <- yacas(expression(z*z))[[1]] f(4) ## [1] 1

Re: [R] require help

2017-09-21 Thread Gabor Grothendieck
Assuming the input data.frame, DF, is of the form shown reproducibly in the Note below, to convert the series to zoo or ts: library(zoo) # convert to zoo z <- read.zoo(DF) # convert to ts as.ts(z) # Note: DF <- structure(list(year = c(1980, 1981, 1982, 1983, 1984), cnsm = c(174, 175, 175, 17

Re: [R] Time series: xts/zoo object at annual (yearly) frequency

2017-10-06 Thread Gabor Grothendieck
Maybe one of these are close enough: xts(c(2, 4, 5), yearqtr(1991:1993)) as.xts(ts(c(2, 4, 5), 1991)) of if you want only a plain year as the index then then use zoo, zooreg or ts class: library(zoo) zoo(c(2, 4, 5), 1991:1993) zooreg(c(2, 4, 5), 1991) ts(c(2, 4, 5), 1991) On Fri,

Re: [R] Concatenate two lists replacing elements with the same name.

2016-07-19 Thread Gabor Grothendieck
Try this: Reduce(modifyList, list(x, y, z)) On Tue, Jul 19, 2016 at 12:34 PM, Luca Cerone wrote: > Dear all, > I would like to know if there is a function to concatenate two lists > while replacing elements with the same name. > > For example: > > x <- list(a=1,b=2,c=3) > y <- list( b=4, d=5

Re: [R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread Gabor Grothendieck
Just replacing lm with a faster version would speed it up. Try lm.fit or even faster is fastLm in the RcppArmadillo package. On Thu, Jul 21, 2016 at 2:02 PM, jeremiah rounds wrote: > Hi, > > A not unusual task is performing a multiple regression in a rolling window > on a time-series.A stand

Re: [R] C/C++/Fortran Rolling Window Regressions

2016-07-21 Thread Gabor Grothendieck
I would be careful about making assumptions regarding what is faster. Performance tends to be nonintuitive. When I ran rollapply/lm, rollapply/fastLm and roll_lm on the example you provided rollapply/fastLm was three times faster than roll_lm. Of course this could change with data of different di

Re: [R] stfrtime function not returning proper results through sqldf package in R

2016-09-16 Thread Gabor Grothendieck
To be precise it's SQLite that does not have date and time data types. If you use an sqldf backend such as H2 that does have such types then sqldf will pass them as such. In the case of R's "Date" class such objects are passed to SQLite as numbers since that is what SQLite can understand but they

[R] Fwd: stfrtime function not returning proper results through sqldf package in R

2016-09-16 Thread Gabor Grothendieck
1. Convert the date from R's origin to the origin used by SQLite's strftime function and then be sure you are using the correct SQLite strftime syntax: library(sqldf) sqldf("select strftime('%m', Date + 2440588.5) month from log") 2. Alternately use the H2 backend which actually supports

Re: [R] Toronto CRAN mirror 403 error?

2015-05-29 Thread Gabor Grothendieck
On Fri, May 29, 2015 at 10:12 PM, Mark Drummond wrote: > I've been getting a 403 when I try pulling from the Toronto CRAN mirror > today. > > http://cran.utstat.utoronto.ca/ > > Is there a contact list for mirror managers? > See the cran_mirrors.csv file in R.home("doc") of your R distribution.

Re: [R] help for lay person assisting R user with disability

2015-06-18 Thread Gabor Grothendieck
On Thu, Jun 18, 2015 at 10:32 AM, Courtney Bryant wrote: > Good Morning, > I am currently working with a disabled R user who is a student here at > CMU. The student has both sight and mobility issues. The student has > asked for an assistant who is well versed in R to enter data for her, which

Re: [R] Spline Graphs

2015-06-29 Thread Gabor Grothendieck
Sorry if this appears twice but I am not sure the first attempt got through. This is not much to go on but here is a short self contained example which creates a longitudinal data frame L in long form from the built in data frame BOD and then plots it as points and splines using lattice: L <- rbi

Re: [R] : Ramanujan and the accuracy of floating point computations - using Rmpfr in R

2015-07-04 Thread Gabor Grothendieck
You can do that with bc if you pass the entire expression to bc(...) in quotes but in that case you will have to use bc notation, not R notation so, for example, exp is e and atan is a. > library(bc) > bc("e(sqrt(163)*4*a(1))") [1] "262537412640768743.2500725971981856888793538563373369

Re: [R] How to create a time series object with time only (no date)

2014-12-21 Thread Gabor Grothendieck
On Sun, Dec 21, 2014 at 12:09 AM, ce wrote: > > Dear all, > > I want to create a time series object from 00:00:00 to 23:59:00 without dates > ? > I can't figure it out with xts ? > This uses zoo, rather than xts: library(zoo) library(chron) tt <- seq(times("00:00:00"), times("23:59:00"), by =

Re: [R] ave(x, y, FUN=length) produces character output when x is character

2014-12-25 Thread Gabor Grothendieck
On Thu, Dec 25, 2014 at 1:57 PM, Mike Miller wrote: > I do think I get what is going on with this, but why should I buy into this > conceptualization? Why is it better to say that a matrix *is* a vector than > to say that a matrix *contains* a vector? The latter seems to be the more > common way

Re: [R] Evaluating a formula

2015-01-16 Thread Gabor Grothendieck
On Fri, Jan 16, 2015 at 3:16 AM, philippe massicotte wrote: > Hi all. > > How we evaluate a formula in R? > > Ex.: > > params <- list(a = 2, b = 3) > x <- seq(1,10, length.out = 100) > > func1 <- as.formula("y ~ a*x^2 + b*x") > > ##How to evaluate func1 using x and the params list > ??? > > > Than

Re: [R] Dropping time series observations

2015-01-31 Thread Gabor Grothendieck
On Sat, Jan 31, 2015 at 2:16 PM, Mikael Olai Milhøj wrote: > Hi > > Is there an easy way to drop, for instance, the first 4 observation of a > time series object in R? I have tried to google the answer without any > luck. > > To be more clear: > Let us say that I have a time seres object x which d

Re: [R] Superscript in legend without using expression function

2015-02-08 Thread Gabor Grothendieck
On Sat, Feb 7, 2015 at 4:57 PM, jgui001 wrote: > I am plotting three sets of data on a single graph, and doing around 100+ > graphs. > I can use the expression function to superscript the 2 but that seems to > force me to manually put in the R squared values. Is there away around this? > > This co

Re: [R] sqldf() difference between R 3.1.2 and 3.0.1

2015-02-11 Thread Gabor Grothendieck
On Wed, Feb 11, 2015 at 9:45 AM, Doran, Harold wrote: > I have a function written and tested using R 3.0.1 and sqldf_0.4-7.1 that > works perfectly. However, using this same code with R 3.1.2 and sqldf_0.4-10 > yields the error below that I am having a difficult time deciphering. Hence, > same

Re: [R] Substring replacement in string

2015-02-28 Thread Gabor Grothendieck
On Fri, Feb 27, 2015 at 5:19 PM, Alrik Thiem wrote: > I would like to replace all lower-case letters in a string that are not part > of certain fixed expressions. For example, I have the string: > > "pmin(pmax(pmin(x1, X2), pmin(X3, X4)) == Y, pmax(Z1, z1))" > > Where I would like to replace all l

Re: [R] Substring replacement in string

2015-02-28 Thread Gabor Grothendieck
x(pmin(a,B),pmin(a,C,d))==Y,pmax(E,e))" > > i.e., with strings where there're no integers following the components in the > pmin/pmax functions. Could this be generalized to handle both cases? > > Best wishes, > Alrik > > -Ursprüngliche Nachricht- > Von: Ga

Re: [R] Extract month and year as one column

2015-03-13 Thread Gabor Grothendieck
On Fri, Mar 13, 2015 at 11:36 AM, Kumsaa wrote: > How could I extract both month and year from a date? I know how to > separately extract both using lubridate package: > > df$month <- month(df$date) > df$year<- year(df$date) > > I wish to extract year and month as one column > >> dput(mydf) > stru

Re: [R] plotmath and logical operators?

2018-08-21 Thread Gabor Grothendieck
Try this: plot(1) tmp <- x >= 3 ~ "&" ~ y <= 3 mtext(tmp) On Mon, Aug 20, 2018 at 5:00 PM MacQueen, Don via R-help wrote: > > I would like to use plotmath to annotate a plot with an expression that > includes a logical operator. > > ## works well > tmp <- expression(x >= 3) > plot(1) > mtext(tmp

Re: [R] looking for formula parser that allows coefficients

2018-08-22 Thread Gabor Grothendieck
Some string manipulation can convert the formula to a named vector such as the one shown at the end of your post. library(gsubfn) # input fo <- y ~ 2 - 1.1 * x1 + x3 - x1:x3 + 0.2 * x2:x2 pat <- "([+-])? *(\\d\\S*)? *\\*? *([[:alpha:]]\\S*)?" ch <- format(fo[[3]]) m <- matrix(strapplyc(ch, pat)[

Re: [R] looking for formula parser that allows coefficients

2018-08-24 Thread Gabor Grothendieck
11:50 AM Paul Johnson wrote: > > Thanks as usual. I owe you more KU decorations soon. > On Wed, Aug 22, 2018 at 2:34 AM Gabor Grothendieck > wrote: > > > > Some string manipulation can convert the formula to a named vector such as > > the one shown at the end of your

Re: [R] looking for formula parser that allows coefficients

2018-08-24 Thread Gabor Grothendieck
The isChar function used in Parse is: isChar <- function(e, ch) identical(e, as.symbol(ch)) On Fri, Aug 24, 2018 at 10:06 PM Gabor Grothendieck wrote: > > Also here is a solution that uses formula processing rather than > string processing. > No packages are used. > >

Re: [R] year and week to date - before 1/1 and after 12/31

2018-10-18 Thread Gabor Grothendieck
Replace the week in the date with week 2, say -- a week in which nothing will go wrong and then add or subtract the appropriate number of weeks. d <- c('2016 00 Sun', '2017 53 Sun', '2017 53 Mon') # test data as.Date(sub(" .. ", "02", d), "%Y %U %a") + 7 * (as.numeric(sub(" (..) ..."

Re: [R] R code for if-then-do code blocks

2018-12-17 Thread Gabor Grothendieck
There is some discussion of approaches to this here: https://stackoverflow.com/questions/34096162/dplyr-mutate-replace-on-a-subset-of-rows/34096575#34096575 On Mon, Dec 17, 2018 at 10:30 AM Paul Miller via R-help wrote: > > Hello All, > > Season's greetings! > > Am trying to replicate some SAS

Re: [R] Newbie Question on R versus Matlab/Octave versus C

2019-01-28 Thread Gabor Grothendieck
R has many similarities to Octave. Have a look at: https://cran.r-project.org/doc/contrib/R-and-octave.txt https://CRAN.R-project.org/package=matconv On Mon, Jan 28, 2019 at 4:58 PM Alan Feuerbacher wrote: > > Hi, > > I recently learned of the existence of R through a physicist friend who > use

Re: [R] [FORGED] Newbie Question on R versus Matlab/Octave versus C

2019-01-28 Thread Gabor Grothendieck
This would be a suitable application for NetLogo. The R package RNetLogo provides an interface. In a few lines of code you get a simulation with graphics. On Mon, Jan 28, 2019 at 7:00 PM Alan Feuerbacher wrote: > > On 1/28/2019 4:20 PM, Rolf Turner wrote: > > > > On 1/29/19 10:05 AM, Alan Feuer

Re: [R] Newbie Question on R versus Matlab/Octave versus C

2019-01-29 Thread Gabor Grothendieck
which is motivated to some degree by Octave but is actually quite different and is particularly suitable in terms of performance for iterative computations where one iteration depends on the prior one. On Mon, Jan 28, 2019 at 6:32 PM Gabor Grothendieck wrote: > > R has many similarities to

Re: [R] Better use with gsub

2014-08-01 Thread Gabor Grothendieck
On Fri, Aug 1, 2014 at 10:46 AM, Doran, Harold wrote: > I have done an embarrassingly bad job using a mixture of gsub and strsplit to > solve a problem. Below is sample code showing what I have to start with (the > vector xx) and I want to end up with two vectors x and y that contain only > the

Re: [R] Old g++ in Rtools

2014-08-06 Thread Gabor Grothendieck
On Wed, Aug 6, 2014 at 2:46 AM, Rguy wrote: > I recently downloaded Rtools. I see the g++ version is > gcc version 4.6.3 20111208 (prerelease) (GCC) > > I also recently downloaded MinGW. Its version of g++ is > gcc version 4.8.1 (GCC) > > I believe that later versions of g++ provide better support

Re: [R] dynamic runSum

2014-08-08 Thread Gabor Grothendieck
On Thu, Aug 7, 2014 at 9:32 AM, amarjit chandhial wrote: > Hello, > runSum calculates a running sum looking back a fixed distance n, e.g. 20. > How do I calculate a dynamic runSum function for an xts object? > In > otherwords, I want to calculate a running sum at each point in time > looking back

Re: [R] R Package for Text Manipulation

2014-08-09 Thread Gabor Grothendieck
On Sat, Aug 9, 2014 at 8:15 AM, Omar André Gonzáles Díaz wrote: > Hi all, > > I want to know, where i can find a package to simulate the functions > "Search and Replace and "Find Words that contain - replace them with...", > that we can use in EXCEL. > > I've look in other places and they say: "R

Re: [R] Sldf command returns negative value for date

2014-08-14 Thread Gabor Grothendieck
On Thu, Aug 14, 2014 at 3:47 PM, Sneha Bishnoi wrote: > Hi All! > > I am trying to increment date column of data frame so as to merge it with > another data frame using sqldf: > my query is : > merge<-sqldf("select m.* ,e.* from mdata as m left join event as e on > date(m.Datest,'+1 day')=e.Start"

Re: [R] Bus stop sequence matching problem

2014-08-30 Thread Gabor Grothendieck
Try dtw. First convert ref to numeric since dtw does not handle character input. Then align using dtw and NA out repeated values in the alignment. Finally zap ugly row names and calculate loading: library(dtw) s1 <- as.numeric(stop_sequence$ref) s2 <- as.numeric(factor(as.character(stop_onoff$r

Re: [R] Operator proposal: %between%

2014-09-05 Thread Gabor Grothendieck
On Thu, Sep 4, 2014 at 10:41 AM, Torbjørn Lindahl wrote: > Not sure if this is the proper list to propose changes like this, if it > passes constructive criticism, it would like to have a %between% operator > in the R language. > There is a between function in the data.table package. > library(d

Re: [R] Import data from Excel to R

2014-09-09 Thread Gabor Grothendieck
On Tue, Sep 9, 2014 at 4:48 PM, JAWADI Fredj wrote: > Hi > I am a New user of R. > Please, how to import data from Excel to R? > Thanks, > Best regards, > Fredj, > There are some ways listed here: https://web.archive.org/web/20131109195709/http://rwiki.sciviews.org/doku.php?id=tips:data-io:ms_win

Re: [R] Using sqldf() to read in .fwf files

2014-09-15 Thread Gabor Grothendieck
On Mon, Sep 15, 2014 at 12:09 PM, Doran, Harold wrote: > I am learning to use sqldf() to read in very large fixed width files that > otherwise do not work efficiently with read.fwf. I found the following > example online and have worked with this in various ways to read in the data > > cat("1 8.

Re: [R] Using sqldf() to read in .fwf files

2014-09-15 Thread Gabor Grothendieck
On Mon, Sep 15, 2014 at 3:23 PM, Doran, Harold wrote: > Thank you, Gabor. This has seemingly resolved the issue. Perhaps a quick > follow up. Suppose I know that the 1st variable I am reading in is to be > numeric and the second is character. Can that be specified in the substr() > argument? >

Re: [R] Savitzky-Golay Smoother

2014-09-26 Thread Gabor Grothendieck
On Fri, Sep 26, 2014 at 3:32 AM, Erick Okuto wrote: > Dear Paul and Henrik, > I have a time series with some missing data points that i need smoothed > using Savitzky-Golay filter. Related question was asked here > http://thr3ads.net/r-help/2012/11/2121748-Savitzky-Golay-filtering-with-missing-da

Re: [R] Could someone recommend a package for time series?

2014-09-29 Thread Gabor Grothendieck
On Mon, Sep 29, 2014 at 5:05 AM, jpm miao wrote: > Hi, > >I've not used R for about one year and don't know well about the updates > on the time series-related package. > > My primary job is to do economic/financial time series data analysis - > annual, monthly, daily, etc. I usually read da

Re: [R] Count number of Fridays in a month

2014-10-10 Thread Gabor Grothendieck
On Fri, Oct 10, 2014 at 7:28 AM, Abhinaba Roy wrote: > Hi R helpers, > > I want to write a function which will > > 1. Count the number of fridays in the current month ( to extract month from > given date) and also the number of fridays in the preceeding month > > 2. Calculate the ratio of the numb

Re: [R] ggplot "scale_x_date" : to plot quarterly scale?

2014-10-14 Thread Gabor Grothendieck
On Tue, Oct 14, 2014 at 3:36 AM, jpm miao wrote: > Hi, > > I am plotting time series by ggplot2, but I believe that my question > applies to other plotting tool as well. > > I want to make my x-axis the quarterly scale, e.g: > 2000Q1 2000Q2. > >However, scale_x_date and date_format("%

Re: [R] Ways to get all function signatures of a library?

2014-10-29 Thread Gabor Grothendieck
On Wed, Oct 29, 2014 at 9:09 AM, Thorsten Jolitz wrote: > > Hi List, > > are there ways to get signatures of all functions of a library in a > format that is easy to process by a programm (list, xml or so)? > > The info about function name, return value and arguments (types) is all > there in the

Re: [R] extracting every nth character from a string...

2015-09-06 Thread Gabor Grothendieck
This uses a regular expression but is shorter: > gsub("(.).", "\\1", "ABCDEFG") [1] "ACEG" It replaces each successive pair of characters with the first of that pair. If there is an odd number of characters then the last character is not matched and therefore kept -- thus it works properly for b

Re: [R] How to read CSV from web?

2015-09-14 Thread Gabor Grothendieck
Your read.csv call works for me under Windows on "R version 3.2.2 Patched (2015-08-25 r69180)" but not on "R version 3.1.3 Patched (2015-03-16 r68169)". Suggest you upgrade your R installation and try again. If you are on Windowsw and don't want to upgrade right now an alternative is to issue th

Re: [R] How to coerce a parameter in nls?

2015-09-21 Thread Gabor Grothendieck
Express the formula in terms of simple operations like this: # add 0/1 columns ref.1, ref.2, ..., ref.6 dproot2 <- do.call(data.frame, transform(dproot, ref = outer(dproot$ref, seq(6), "==") + 0)) # now express the formula in terms of the new columns library(nlmrt) fitdp1<-nlxb(den ~ (Rm1 * ref.1

Re: [R] How to coerce a parameter in nls?

2015-09-22 Thread Gabor Grothendieck
y function. I tried some > times but am not sure how to improve it because I am quite new to R. > > Could anyone please give me some suggestion. > > Thanks a lot! > > > Jianling > > > On 22 September 2015 at 00:43, Gabor Grothendieck > wrote: > > Express the f

Re: [R] How to coerce a parameter in nls?

2015-09-22 Thread Gabor Grothendieck
01, Rm2=1.01, Rm3=1.01, Rm4=6.65, Rm5=1.01, Rm6=1, d50=20, c=-1)) On Tue, Sep 22, 2015 at 7:04 AM, Gabor Grothendieck wrote: > Just write out the 20 terms. > > On Mon, Sep 21, 2015 at 10:26 PM, Jianling Fan > wrote: > >> Hello, Gabor, >> >> Thanks again for your

Re: [R] How to coerce a parameter in nls?

2015-09-22 Thread Gabor Grothendieck
You may have to do without masking and switch back to nls. dproot2 and fo are from prior post. # to mask Rm6 omit it from start and set it explicitly st <- c(Rm1=1.01, Rm2=1.01, Rm3=1.01, Rm4=6.65, Rm5=1.01, d50=20, c=-1) Rm6 <- 1 fm.nls <- nls(fo, dproot2, start = st) AIC(fm.nls) summary(fm.nl

Re: [R] flatten a list

2015-09-29 Thread Gabor Grothendieck
> do.call(c, lapply(temp, function(x) if (is.list(x)) x else list(x))) [[1]] [1] 1 2 3 [[2]] [1] "a" "b" "c" $duh [1] 5 6 7 8 $zed [1] 15 16 17 On Tue, Sep 29, 2015 at 11:00 AM, Therneau, Terry M., Ph.D. < thern...@mayo.edu> wrote: > I'd like to flatten a list from 2 levels to 1 level. This

Re: [R] Most appropriate function for the following optimisation issue?

2015-10-20 Thread Gabor Grothendieck
Yes, it's the projection of S onto the subspace orthogonal to B which is: X <- S - B%*%B / sum(B*B) and is also implied by Duncan's solution since that is what the residuals of linear regression are. On Tue, Oct 20, 2015 at 1:00 PM, Paul Smith wrote: > On Tue, Oct 20, 2015 at 11:58 AM, Andy Yu

Re: [R] Most appropriate function for the following optimisation issue?

2015-10-20 Thread Gabor Grothendieck
Correction. Yes, it's the projection of S onto the subspace orthogonal to B which is: X <- S - (B%o%B) %*% S/ sum(B*B) and is also implied by Duncan's solution since that is what the residuals of linear regression are. On Tue, Oct 20, 2015 at 1:11 PM, Gabor Grothendieck wrote:

Re: [R] Linear regression with a rounded response variable

2015-10-21 Thread Gabor Grothendieck
This could be modeled directly using Bayesian techniques. Consider the Bayesian version of the following model where we only observe y and X. y0 is not observed. y0 <- X b + error y <- round(y0) The following code is based on modifying the code in the README of the CRAN rcppbugs R package.

Re: [R] Optim() and Instability

2015-11-14 Thread Gabor Grothendieck
Tyipcally the parameters being optimized should be the same order of magnitude or else you can expect numerical problems. That is what the fnscale control parameter is for. On Sat, Nov 14, 2015 at 10:15 AM, Lorenzo Isella wrote: > Dear All, > I am using optim() for a relatively simple task: a li

Re: [R] Optim() and Instability

2015-11-14 Thread Gabor Grothendieck
I meant the parscale parameter. On Sat, Nov 14, 2015 at 10:30 AM, Gabor Grothendieck wrote: > Tyipcally the parameters being optimized should be the same order of > magnitude or else you can expect numerical problems. That is what the > fnscale control parameter is for. > > On Sa

Re: [R] Optim() and Instability

2015-11-16 Thread Gabor Grothendieck
] 0.6305 -0.1247 -0.0032 $ value : num 473 <= $ counts : Named int [1:2] 182 NA ..- attr(*, "names")= chr [1:2] "function" "gradient" $ convergence: int 0 $ message: NULL On Sat, Nov 14, 2015 at 10:32 AM, Gabor Grothendieck wrote: > I me

Re: [R] fancy linear model and grouping

2016-02-02 Thread Gabor Grothendieck
Try the mclust package: library(mclust) temp.na <- na.omit(temp) fm <- Mclust(temp.na) g <- fm$classification plot(temp.na, pch = g, col = g) On Tue, Feb 2, 2016 at 6:35 AM, PIKAL Petr wrote: > Dear all > > I have data like this > >> dput(temp) > > temp <- structure(list(X1 = c(93, 82, NA, 93,

Re: [R] fancy linear model and grouping

2016-02-02 Thread Gabor Grothendieck
> problem. > > Here is the result with whole data. > > fm <- Mclust(temp) > g <- fm$classification > plot(1/temp[,1], temp[,2], pch = g, col = g) > > I will go through the docs more thoroughly, to be 100% sure I did not miss > anything. > > Cheers > Petr &

Re: [R] Create macro_var in R

2016-02-03 Thread Gabor Grothendieck
See Example 5. Insert Variables on the sqldf home page. https://github.com/ggrothendieck/sqldf On Wed, Feb 3, 2016 at 2:16 PM, Amoy Yang via R-help wrote: > First, MVAR<-c("population) should be the same as "population'". Correct? > You use tab[[MVAR]] to refer to "population" where doub

Re: [R] sqldf --Warning message:

2016-02-19 Thread Gabor Grothendieck
sqldf does not use Tk so you can ignore this. On Fri, Feb 19, 2016 at 12:32 PM, Divakar Reddy wrote: > Dear R users, > > I'm getting Waring message while trying to load "sqldf" package in R3.2.3 > and assuming that we can ignore this as it's WARNING Message and not an > error message. > Can you g

Re: [R] Functional programming?

2016-03-02 Thread Gabor Grothendieck
This manufactures the functions without using eval by using substitute to substitute i-1 and a[i] into an expression for the body which is then assigned to the body of the function: hh <- vector("list", 5) hh[[1]] <- f(a[1]) for(i in 2:5) { hh[[i]] <- hh[[1]] body(hh[[i]]) <- substitute(

Re: [R] Linear Regressions with constraint coefficients

2016-04-26 Thread Gabor Grothendieck
This is a quadratic programming problem that you can solve using either a quadratic programming solver with constraints or a general nonlinear solver with constraints. See https://cran.r-project.org/web/views/Optimization.html for more info on what is available. Here is an example using a nonline

Re: [R] Approximate taylor series

2016-04-27 Thread Gabor Grothendieck
Regress on a multivariate polynomial: lm(y ~ polym(x1, x2, x3, x4, degree = 3)) See ?polym __ 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

Re: [R] Linear Regressions with constraint coefficients

2016-04-28 Thread Gabor Grothendieck
ive Analyst - Convertibles > aljosa.aleksandro...@man.com > Tel +41 55 417 76 03 > > Man Investments (CH) AG > Huobstrasse 3 | 8808 Pfäffikon SZ | Switzerland > > -Original Message- > From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] > Sent: Dienstag, 26. Apri

Re: [R] Clean method to convert date and time between time zones keeping it in POSIXct format

2016-05-09 Thread Gabor Grothendieck
This involves mucking with the internals as well but it is short: structure(T1, tzone = "UTC") On Mon, May 9, 2016 at 9:24 AM, Arnaud Mosnier wrote: > Dear UseRs, > > I know two ways to convert dates and time from on time zone to another but > I am pretty sure that there is a better (cleaner)

Re: [R] break string at specified possitions

2016-05-17 Thread Gabor Grothendieck
Here are two ways that do not use any packages: s <- paste(letters, collapse = "") # test input substring(s, first, last) ## [1] "abcde" "fghij" "klmnopqrs" read.fwf(textConnection(s), last - first + 1) ## V1V2V3 ## 1 abcde fghij klmnopqrs On Wed, May 11, 2016 at 4:

Re: [R] Finding starting values for the parameters using nls() or nls2()

2016-10-09 Thread Gabor Grothendieck
If you are not tied to that model the SSasymp() model in R could be considered and is easy to fit: # to plot points in order o <- order(cl$Area) cl.o <- cl[o, ] fm <- nls(Retention ~ SSasymp(Area, Asym, R0, lrc), cl.o) summary(fm) plot(Retention ~ Area, cl.o) lines(fi

Re: [R] Split strings based on multiple patterns

2016-10-15 Thread Gabor Grothendieck
Replace newlines and colons with a space since they seem to be junk, generate a pattern to replace the attributes with a comma and do the replacement and finally read in what is left into a data frame using the attributes as column names. (I have indented each line of code below by 2 spaces so if

Re: [R] abline with zoo series

2016-11-24 Thread Gabor Grothendieck
Recessions are typically shown by shading. The zoo package has xblocks for this purpose. If app1 is your zoo object then: plot(app1) tt <- time(app1) xblocks(tt, tt >= "1990-07-01" & tt <= "1991-03-31", col = rgb(0.7, 0.7, 0.7, 0.5)) # transparent grey See ?xblocks for more info. On Thu,

Re: [R] Matrix

2017-03-07 Thread Gabor Grothendieck
Assuming that the input is x <- 1:4, try this one-liner: > embed(c(0*x[-1], x, 0*x[-1]), 4) [,1] [,2] [,3] [,4] [1,]1000 [2,]2100 [3,]3210 [4,]4321 [5,]0432 [6,]0043 [7,]0004 On Mo

Re: [R] nlmrt problems - No confInt, NA StdErr, t-, or p-values

2017-03-21 Thread Gabor Grothendieck
You can use wrapnls from the nlmrt package to get an nls object. Run it instead of nlxb. It runs nlxb followed by nls so that the output is an nls object.. Then you can use all of nls' methods. On occiasion that fails even if nlxb succeeds since the nls optimization can fail independently of nlx

Re: [R] barchart with bars attached to y=0-line

2008-07-16 Thread Gabor Grothendieck
You could do it without a panel function using xyplot and type "h" : df2 <- transform(df, Compound = factor(abbreviate(Compound))) xyplot(Ratio ~ Compound | Class, df2, type = c("h", "g"), lwd = 7, par.settings = list(grid.pars = list(lineend = 1))) On Wed, Jul 16, 2008 at 6:48 AM, Henni

Re: [R] date to decimal date conversion

2008-07-16 Thread Gabor Grothendieck
Its not clear from your post what the decimal portion is supposed to represent since Feb is not 35% of the way through the year but in any case see R News 4/1 and the full page table at the end of that article, in particular, for some date idioms that you can use. On Wed, Jul 16, 2008 at 7:41 AM,

Re: [R] RSQLite maximum table size

2008-07-16 Thread Gabor Grothendieck
It depends on what the values for certain variables were set to when it was compiled. See: http://www.sqlite.org/limits.html On Wed, Jul 16, 2008 at 4:14 PM, Vidhu Choudhary <[EMAIL PROTECTED]> wrote: > Hi All, > I am trying to make write a table in RSQLite. And I get the error mentioned > below

Re: [R] finding "chuncks" of data that have no NA s

2008-07-18 Thread Gabor Grothendieck
na.contiguous.zoo() will return the longest stretch of non-NA data. Its a zoo method of the na.contiguous generic in the core of R. rle(!is.na(rowSums(coredata(z will find all stretches. On Fri, Jul 18, 2008 at 6:47 AM, stephen sefick <[EMAIL PROTECTED]> wrote: > I have a data frame that is 1

Re: [R] finding "chuncks" of data that have no NA s

2008-07-18 Thread Gabor Grothendieck
E, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, > TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, > TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, > TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, > TRUE, FALSE, TRUE, FALSE, TRUE, FAL

Re: [R] How to cut data elements included in a text line

2008-07-18 Thread Gabor Grothendieck
strapply in gsubfn finds matches of the indicated regexp, in this case a \t followed by one or more minus, dot or digit, and with backref of -1 it passes the backreference, i.e. portion of the match within (..), to the function in the third arg. See http://gsubfn.googlecode.com library(gsubfn) st

Re: [R] Change font-face in title

2008-07-19 Thread Gabor Grothendieck
Try this: plot(1, type="l", xlab="Wellenlänge [nm]", col="darkslategray", main = ~ Spektrum ~ italic(Deschampsia ~ caespitosa)) On Sat, Jul 19, 2008 at 11:31 AM, Albin Blaschka <[EMAIL PROTECTED]> wrote: > > > Dear List, > > Is there a possibility to change the font-face for a part of the ti

Re: [R] Change font-face in title

2008-07-19 Thread Gabor Grothendieck
Or this which looks slightly better: plot(1, type="l", xlab="Wellenlänge [nm]", col="darkslategray", main = ~ Spektrum ~ italic("Deschampsia caespitosa")) On Sat, Jul 19, 2008 at 11:56 AM, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: >

Re: [R] extracting colnames to label plots in a function

2008-07-19 Thread Gabor Grothendieck
See ?paste and the collapse argument, in particular: plot(d, main = paste(paste(colnames(x), collapse = " "), paste(colnames(y), collapse = " "), sep = " - ")) Also your function sets na.method but never uses it and leaves the par settings changed afterwards. See ?par. It could also

Re: [R] extracting colnames to label plots in a function

2008-07-19 Thread Gabor Grothendieck
es section of ?match.arg . Note that the choices are best placed in the formal parameter list, not in the match.arg function. > > On Sat, Jul 19, 2008 at 12:36 PM, Gabor Grothendieck > <[EMAIL PROTECTED]> wrote: >> >> See ?paste and the collapse argument, in

Re: [R] Non-linearly constrained optimisation

2008-07-19 Thread Gabor Grothendieck
The Ryacas package is an interface between R and the computer algebra system, yacas. It includes an R to yacas parser/translator and an OpenMath/XML to R parser/translator. See: http://ryacas.googlecode.com On Sat, Jul 19, 2008 at 11:03 PM, Stuart Nettleton <[EMAIL PROTECTED]> wrote: > Tolga, > Y

Re: [R] estimating volume from xyz points

2008-07-20 Thread Gabor Grothendieck
On Sat, Jul 19, 2008 at 5:21 PM, milton ruser <[EMAIL PROTECTED]> wrote: > Dear all, > > I have several sets of x-y-z points and I need to estimate the volume that > encompass all my points. > Recently I got some adivice to show the "convex hull" of my points using > geometry package (see code belo

Re: [R] Conditionally Updating Lattice Plots

2008-07-20 Thread Gabor Grothendieck
Try this: library(lattice) fancy.lm <- function(x, y, fit = TRUE, resid = TRUE){ model <- lm(y ~ x) y.pred <- predict(model) # Compute residuals for plotting res.x <- as.vector(rbind(x, x, rep(NA,length(x # NAs induce breaks in line res.y <- as.vector(rbind(

  1   2   3   4   5   6   7   8   9   10   >