[R] lattice xyplot with cumsum() function inside

2024-09-28 Thread Naresh Gurbuxani
This code gives unexpected result. library(data.table) library(lattice) set.seed(123) mydt <- data.table(date = seq.Date(as.IDate("2024-01-01"), by = 1, length.out = 50), xgroup = "A", x = runif(50, 0, 1)) mydt <- rbindlist(list(mydt, data.table(date = mydt$date, xgroup = "B", x = runif(50, 0,

Re: [R] store list objects in data.table

2024-09-22 Thread Naresh Gurbuxani
), .(fit)][[1]][[1]] |> summary() carsreg3[, .(rsq = summary(fit[[1]])$r.squared), by = .(cyl)] #   cyl   rsq #1:   6 0.7217114 #2:   4 0.7080702 #3:   8 0.4970692 data.table is a fantastic tool. Thanks again, Naresh On 9/22/24 07:44, Naresh Gurbuxani wrote: Thanks everyone for their res

Re: [R] store list objects in data.table

2024-09-22 Thread Naresh Gurbuxani
l free to ignore without replying if my gratuitous remarks are unhelpful. Cheers, Bert On Sat, Sep 21, 2024 at 2:25 PM Naresh Gurbuxani wrote: I am trying to store regression objects in a data.table df <- data.frame(x = rnorm(20)) df[, "y"] <- with(df, x + 0.1 * x^2 + 0.2 * rn

[R] store list objects in data.table

2024-09-21 Thread Naresh Gurbuxani
I am trying to store regression objects in a data.table df <- data.frame(x = rnorm(20)) df[, "y"] <- with(df, x + 0.1 * x^2 + 0.2 * rnorm(20)) mydt <- data.table(mypower = c(1, 2), myreg = list(lm(y ~ x, data = df), lm(y ~ x + I(x^2), data = df))) mydt #   mypower    myreg #    #1:   1

[R] Strange variable names in factor regression

2024-05-09 Thread Naresh Gurbuxani
On converting character variables to ordered factors, regression result has strange names. Is it possible to obtain same variable names with and without intercept? Thanks, Naresh mydf <- data.frame(date = seq.Date(as.Date("2024-01-01"), as.Date("2024-03-31"), by = 1)) mydf[, "wday"] <- weekday

Re: [R] combine barchart and xyplot in lattice

2023-11-18 Thread Naresh Gurbuxani
 AM, Deepayan Sarkar > wrote: > > On Sat, 18 Nov 2023 at 06:44, Naresh Gurbuxani > wrote: >> >> In below graph, I would like to add two vertical lines using >> panel.abline(). Is this possible? > > I assume you want the 'v' variable in panel.abline()

[R] combine barchart and xyplot in lattice

2023-11-18 Thread Naresh Gurbuxani
In below graph, I would like to add two vertical lines using panel.abline().  Is this possible? Thanks, Naresh mydf <- data.frame(hour = rep(6:20, 2), traffic = c(round(dnorm(6:20, 9, 3) * 1), round(dnorm(6:20, 17, 4) * 1)), direction = rep(c("inbound", "outbound"), c(15, 15))) vehicles

[R] lattice densityplot with weights

2023-09-29 Thread Naresh Gurbuxani
density() function in R accepts weights as an input. Using this function, one can calculate density and plot it. Is it possible to combined these two operations in lattice densityplot()? mydf <- data.frame(name = "A", x = seq(-2.9, 2.9, by = 0.2), wt = diff(pnorm(seq(-3, 3, by = 0.2 mydf <

Re: [R] RQuantLib installation problem

2023-09-26 Thread Naresh Gurbuxani
Updating to latest version of R and reinstalling RQuantLib worked. Thanks > On Sep 24, 2023, at 5:29 PM, David Winsemius wrote: > > > On 9/24/23 08:23, Ivan Krylov wrote: >> On Sun, 24 Sep 2023 02:19:20 + >> Naresh Gurbuxani wrote: >> >>>> in

Re: [R] data.table installation on intel macOS Ventura 13.6

2023-09-26 Thread Naresh Gurbuxani
y dedicated for Mac. > • https://github.com/Rdatatable/data.table/wiki/Installation > > You will see that you will most likely have to modify the "Makevars" file to > include the paths of different compilers. > > Thank you, > Carlos. > > On Mon, Sep 25, 2

[R] data.table installation on intel macOS Ventura 13.6

2023-09-24 Thread Naresh Gurbuxani
My data.table installation uses single thread only. Instruction on this site do not apply to Ventura 13.6 https://github.com/Rdatatable/data.table/wiki/Installation Has anyone got data.table working with multi-thread? Thanks, Naresh __ R-help@r-proj

[R] RQuantLib installation problem

2023-09-23 Thread Naresh Gurbuxani
In my mac, using brew, I installed boost and quantlib packages. But installation of RQuantLib errored out because R could not find libgfortran.5.dylib My mac does have this file, but in a different location. Is there a simple fix to install RQuantLib? Thanks, Naresh ~ $ ls /usr/local/gfortran

Re: [R] unable to load latticeExtra in AWS R

2023-09-11 Thread Naresh Gurbuxani
Reinstall of jpeg followed by reinstall of latticeExtra solved this problem. Thanks Sent from my iPhone > On Sep 8, 2023, at 6:34 PM, Ivan Krylov wrote: > > 8 сентября 2023 г. 22:25:10 UTC, Naresh Gurbuxani > пишет: >>> library(latticeExtra) >> Error: package o

[R] unable to load latticeExtra in AWS R

2023-09-08 Thread Naresh Gurbuxani
In my AWS Sagemaker account latticeExtra does not load. It has worked in the past. How can this problem be fixed? Thanks, Naresh Sent from my iPhone Begin forwarded message: Lattice package is preinstalled. I installed latticeExtra. > .libPaths() [1] "/home/ec2-user/SageMaker/R-library" [

[R] data.table question

2023-08-30 Thread Naresh Gurbuxani
I want to apply interpolation functions from one data.table to each row of another data.table. interp.dt <- data.table(scen = rep(c("a", "b"), c(3, 3)), term = c(1, 20, 60, 1, 32, 72), shock = c(10, 20, 30, 9, 12, 32)) interp.fn <- function(df, x) with(df, approx(term, shock, xout = x)$y) mydt

Re: [R] Merge with closest (not equal) time stamps

2023-08-24 Thread Naresh Gurbuxani
ham wrote: > > It sounds like you might want a rolling join, e.g. > https://dplyr.tidyverse.org/reference/join_by.html#rolling-joins. > > (And data.table has similar functionality which inspired dplyr) > > Hadley > > On Mon, Aug 7, 2023 at 9:32 PM Naresh Gurbuxani &

Re: [R] Merge with closest (not equal) time stamps

2023-08-08 Thread Naresh Gurbuxani
gt; dplyr::select(1,2,4,3) -> > myres2 > > identical(myres, myres2) ## TRUE > > > On Tue, Aug 8, 2023 at 5:32 AM Naresh Gurbuxani > wrote: >> >> >> I have two dataframes, each with a column for timestamp. I want to >> merge the two

[R] Merge with closest (not equal) time stamps

2023-08-07 Thread Naresh Gurbuxani
I have two dataframes, each with a column for timestamp. I want to merge the two dataframes such that each row from first dataframe is matched with the row in the second dataframe with most recent but preceding timestamp. Here is an example. option.trades <- data.frame(timestamp = as.POSIXct(c(

[R] Plot R graphs in aws

2023-04-20 Thread Naresh Gurbuxani
In my Amazon Web Services (AWS) account, I use R via emacs launched from terminal. While R computations work well, viewing graphs is inconvenient. I am not able to use screen device. I can send graphs to a png or pdf file, then open the file. I would like a setup where code is run in one wi

Re: [R] preserve class in apply function

2023-02-07 Thread Naresh Gurbuxani
26504430 0.02037657 > > Cheers > Petr > >> -Original Message- >> From: R-help On Behalf Of Naresh Gurbuxani >> Sent: Tuesday, February 7, 2023 1:52 PM >> To: r-help@r-project.org >> Subject: [R] preserve class in apply function >> >> &

[R] preserve class in apply function

2023-02-07 Thread Naresh Gurbuxani
> Consider a data.frame whose different columns have numeric, character, > and factor data. In apply function, R seems to pass all elements of a > row as character. Is it possible to preserve numeric class? > >> mydf <- data.frame(x = rnorm(10), y = runif(10)) >> apply(mydf, 1, function(row) {

Re: [R] implicit loop for nested list

2023-01-27 Thread Naresh Gurbuxani
lt;- do.call("cbind", mysim["two.mat", ]) > four.mat <- do.call("cbind", mysim["four.mat", ]) > ``` > >> On Thu, Jan 26, 2023 at 10:33 PM Naresh Gurbuxani >> wrote: >> >>> >>> I am looking for a more elegant

[R] implicit loop for nested list

2023-01-26 Thread Naresh Gurbuxani
> > I am looking for a more elegant way to write below code. > > #Simulation results have different dimensions > mysim <- lapply(1:10, function(y) { >two.mat <- matrix(rnorm(4), nrow = 2) >four.mat <- matrix(rnorm(16), nrow = 4) >list(two.mat = two.mat, four.mat = four.mat) #results w

[R] Info files in Windows and Mac distributions

2023-01-22 Thread Naresh Gurbuxani
Recently I installed Linux on my desktop. I discovered that R for Linux ships with info files of manuals. R for Windows and Mac only ship with html and pdf files of manuals. Why not include info files in R distributions for Windows and Mac? These are very convenient with emacs. Using pandoc

[R] replicate results of tree package

2022-10-13 Thread Naresh Gurbuxani
I am trying to understand ``deviance'' in classification tree output from tree package. library(tree) set.seed(911) mydf <- data.frame( name = as.factor(rep(c("A", "B"), c(10, 10))), x = c(rnorm(10, -1), rnorm(10, 1)), y = c(rnorm(10, 1), rnorm(10, -1))) mytree <- tree(name ~ ., da

Re: [R] lattice question

2022-08-12 Thread Naresh Gurbuxani
This is the solution I was looking for. Thanks to Deepayan and Bert for sticking with me. Naresh Sent from my iPhone On Aug 12, 2022, at 8:02 AM, Deepayan Sarkar wrote:  On Thu, Aug 11, 2022 at 9:03 PM Naresh Gurbuxani mailto:naresh_gurbux...@hotmail.com>> wrote: Bert, Than

Re: [R] lattice question

2022-08-10 Thread Naresh Gurbuxani
). Is it possible? Thanks, Narrsh Sent from my iPhone > On Aug 10, 2022, at 9:37 AM, Deepayan Sarkar > wrote: > > On Wed, Aug 10, 2022 at 4:53 PM Naresh Gurbuxani > wrote: >> >> >> I want to merge two panels into one. Is it possible to do this? >&g

Re: [R] Reference factors inside split

2022-07-11 Thread Naresh Gurbuxani
unt) > > myplots <- sapply(names(mydf.split), > function(name, x = NULL) { >df <- x[[name]] >myts <- aggregate(sale ~ date, FUN = sum, data = df) >xyplot(sale ~ date, data = myts, main = name) > }, x = mydf.split, USE.NAMES = TRUE, simplify = FALSE) &g

Re: [R] [External] Sweave

2022-06-26 Thread Naresh Gurbuxani
install it on your own machine then you can continue working as before. From: R-help on behalf of Naresh Gurbuxani Sent: Sunday, June 26, 2022 9:28:41 AM To: r-help@r-project.org Subject: [External] [R] Sweave I want to use Sweave, but incorporate some features

Re: [R] legend in plot

2022-05-06 Thread Naresh Gurbuxani
Hi Naresh, Have a look at the emptyspace function in the plotrix package. This returns the center of the largest empty space on the plot. Jim On Thu, May 5, 2022 at 10:41 PM Naresh Gurbuxani mailto:naresh_gurbux...@hotmail.com>> wrote: > > Is it possible to define legend in the plot c

Re: [R] struccchange on zoo time series

2022-05-01 Thread Naresh Gurbuxani
>>> Time series toolkit with identical behavior for all time series >>>>> classes: 'ts','xts', 'data.frame', 'data.table', 'tibble', 'zoo', >>>>> 'timeSeries', 'tsibble', 'tis&

Re: [R] [External] A simple lattice histogram

2022-04-20 Thread Naresh Gurbuxani
c(0.5, 0, 1, 0.5), more = FALSE) Naresh From: Richard M. Heiberger Sent: Wednesday, April 20, 2022 12:02 PM To: Naresh Gurbuxani Cc: r-help@r-project.org Subject: Re: [External] [R] A simple lattice histogram   start here  library(latticeExtra)  c(histogram(~ card, data=CreditCard), histogr

[R] A simple lattice histogram

2022-04-20 Thread Naresh Gurbuxani
I am struggling with a simple histogram where scales of x-axis should be free.   Each panel should only show the range relevant for data plotted in that panel.   library(lattice) library(AER) data(CreditCard) histogram( ~ card + reports, data = CreditCard, scales = "free") This code creates two p

Re: [R] print only a few lines of an object

2022-03-24 Thread Naresh Gurbuxani
I hit send button too fast.   Thanks for this alternative solution, Naresh From: R-help on behalf of Naresh Gurbuxani Sent: Wednesday, March 23, 2022 6:16 PM To: David Carlson Cc: r-help mailing list ; John Fox Subject: Re: [R] print only a few lines of an object   Sent from my iPhone

Re: [R] print only a few lines of an object

2022-03-23 Thread Naresh Gurbuxani
8604e+00 >> 0.6265465033 >> [2,] -1.693822e+00 2.689917e-01 -1.703176e-01 1.128759e+00 >> -0.7594760299 >> [3,] 1.260585e-01 6.589839e-01 -7.928987e-01 6.430545e-01 >> 1.1951731814 >> [4,] -1.890582e+00 7.614779e-01 -5.726204e-01 1.090881e+00 >

Re: [R] function to return plots

2020-06-12 Thread Naresh Gurbuxani
Thanks for your quick response.  It works as I wanted.  From: Rui Barradas Sent: Friday, June 12, 2020 7:08 AM To: Naresh Gurbuxani ; r-help@r-project.org Subject: Re: [R] function to return plots   Hello, plot.list is a list, try '[[' to access its members. ('[' return

[R] function to return plots

2020-06-12 Thread Naresh Gurbuxani
I want to write a function that will return lattice plots. This simple function output a list of two plots. These plots can be individually shown on the console. But I am unable to put them on two panels of a single plot. What changes do I need to make to this function? Thanks, Naresh libra

[R] where is .emacs file?

2017-03-01 Thread Naresh Gurbuxani
I am trying to install ESS so that it can be used when EMACS is launched from Mac Terminal.  After running "make" from the directory where ESS files are saved, the instructions ask the following to be added to .emacs file: (require 'ess-site) But I cannot find .emacs file. I have already ins

Re: [R] lattice graph with free scales and reversed axis values

2016-11-05 Thread Naresh Gurbuxani
This worked very well for me. Thanks, Naresh From: P Tennant Sent: Saturday, November 5, 2016 7:57 PM To: Naresh Gurbuxani Cc: R-help@r-project.org Subject: Re: [R] lattice graph with free scales and reversed axis values Hi Naresh, You could calculate the

[R] suppress labels in lattice barchart

2016-10-15 Thread Naresh Gurbuxani
I would like to print a barchart without labels for categorical variables.   What change should be made to below command? Thanks, Naresh boy.age <- data.frame(name = c("alpha", "beta", "charlie", "gerald"), age = c(7, 9, 6, 5)) boy.age$name <- with(boy.age, reorder(name, age)) # draws with nam

[R] tikzDevice and Sweave

2016-01-17 Thread Naresh Gurbuxani
I want to use tikz() function in tikzDevice package so that it generates a pdf file to be included in the bigger tex file. Below code works, but directly inserts tikz commands in the output tex file. This works: <>= This does not work: <>= Full code is given below: \documentclass{article}\use

[R] lattice strip.custom function

2015-07-04 Thread Naresh Gurbuxani
I would like to use a mapping to name panel strips. Directly using mapping table does not work. What is the problem here? my.df <- data.frame(x = rnorm(100, mean = 0, sd = 2), name = "A") my.df <- rbind(my.df, data.frame(x = rnorm(100, mean = 0, sd = 4), name = "B")) my.df <- rbind(my.df, data.f

Re: [R] Help with lattice panel function

2015-04-29 Thread Naresh Gurbuxani
pe = "l") >}) > > > 2015-04-29 13:09 GMT+02:00 Naresh Gurbuxani : >> I want to plot multiple variables in xyplot, but plot loess trend for only >> one of these variables. My problem is that the last command below does not >> give the desired

[R] Help with lattice panel function

2015-04-29 Thread Naresh Gurbuxani
I want to plot multiple variables in xyplot, but plot loess trend for only one of these variables. My problem is that the last command below does not give the desired result. Any help will be gratefully received. Thanks,Naresh my.df <- data.frame(date = as.numeric(as.Date("2015-01-01")) + 0:49,

Re: [R] Evaluated expression in lattice key

2015-01-22 Thread Naresh Gurbuxani
panel.xyplot(x, y, ...) > panel.abline(lm(y~x), col="red") > panel.text(1, -1, bquote(R^2 == .(summary(lm(y~x))$r.squared))) >}, >grid = TRUE > ) > > Is this what you are looking for? I hope this helps. > > Chel Hee Lee > > > O

[R] Evaluated expression in lattice key

2015-01-17 Thread Naresh Gurbuxani
In a conditional xyplot, I would like to add some numerical results in every panel. Consider below example. df <- data.frame(x = rnorm(100), name = "A") df <- within(df, {y <- x + 0.2 * rnorm(100)}) df2 <- data.frame(x = rnorm(100), y = rnorm(100), name = "B") df <- rbind(df, df2) rm(df2) with(