Re: [R] graphics useRaster check_irregular definition for date or posix

2021-04-13 Thread Paul Murrell
Hi I doubt it is intended (to deliberately exclude "difftime" objects). Can you please supply a full image() example (with 'x' and/or 'y' as Dates and a 'z') ? So that I can see what ... image(x, y, z, useRaster=FALSE) ... looks like, so I can see what you want ... image(x, y, z,

Re: [R] Looping through data error

2021-04-13 Thread Bert Gunter
Well, if I understand your query, wouldn't the following simple approach suffice -- it assumes that the results for each company are ordered by year, as your example seems to show: ## test is your example data ## first remove NA's test2 <- na.omit(test) ## Now just use tapply(): > out

Re: [R] Looping through data error

2021-04-13 Thread e-mail ma015k3113 via R-help
Rui, excellent diagnosis and suggestion. It worked but my damn logic is still not delivering what I want-will spend more time on it tomorrow. Kind regards Ahson > On 13 April 2021 at 17:06 Rui Barradas wrote: > > > Hello, > > A close parenthesis is missing in the nd if. > > > for (i in

Re: [R] Add a new row based on test set predicted values and time stamps

2021-04-13 Thread Jeff Newmiller
The date you get using as.Date on a POSIXct value depends on the timezone. That is, as.Date only pays attention to the underlying UTC seconds-since-epoch value, so it ignores the timezone which can be unexpected for most people. TL;DR as.Date is not the same as as.POSIXct( trunc( dtm,

Re: [R] Add a new row based on test set predicted values and time stamps

2021-04-13 Thread Bert Gunter
(Revealing my ignorance): Simpler still than the as.POSIXct() idiom is just to use the as.Date version: out <- with(out, out [order(Group, id, as.Date(Date)),]) ## all else the same... Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into

Re: [R] Add a new row based on test set predicted values and time stamps

2021-04-13 Thread Bert Gunter
It may not be necessary to insert the rows in that order -- R can identify and use the information from the rows in in most cases without it. So to combine the results as you described (the code you sent got garbled a bit btw -- you should proofread more carefully in future), all you would need to

[R] graphics useRaster check_irregular definition for date or posix

2021-04-13 Thread cdanek
Hi The function `check_irregular()` defined within `graphics::image.default()` checks if the `useRaster` argument for `graphics::image()` can be true or must be false. According to this function, the following example vector is irregular: ``` time <- seq(as.Date("2020-1-1"),

Re: [R] Looping through data error

2021-04-13 Thread e-mail ma015k3113 via R-help
Jim, thanks for taking the time to look into this. Yes, these if else statements are so confusing. I tried your amended scode and it does not work. The error are as follows: Error: unexpected '}' in " }" > NUMBER_OF_SHARES[i] = 100 / is.na(CLOSE_SHARE_PRICE[i]) > } Error: unexpected '}' in "

Re: [R] Looping through data error

2021-04-13 Thread Rui Barradas
Hello, Typo, inline. Às 17:06 de 13/04/21, Rui Barradas escreveu: Hello, A close parenthesis is missing in the nd if. Should be "the 2nd if". Rui Barradas for (i in 1:(nrow(PLC_Return)-1)){   if (i == 1){     NUMBER_OF_SHARES[i] = 100/is.na(CLOSE_SHARE_PRICE[i])   } else

Re: [R] Looping through data error

2021-04-13 Thread Rui Barradas
Hello, A close parenthesis is missing in the nd if. for (i in 1:(nrow(PLC_Return)-1)){ if (i == 1){ NUMBER_OF_SHARES[i] = 100/is.na(CLOSE_SHARE_PRICE[i]) } else if(is.na(PLC_Return[i, 1]) == is.na(PLC_Return[i + 1, 1])){ NUMBER_OF_SHARES[i]=0 } else { NUMBER_OF_SHARES[i] =

Re: [R] Looping through data error

2021-04-13 Thread jim holtman
Your code was formatted incorrectly. There is always a problem with the 'else' statement after an 'if' since in R there is no semicolon to mark the end of a line. Here might be a better format for your code. I would recommend the liberal use of "{}"s when using 'if/else' i <- 0 for (i in

[R] Looping through data error

2021-04-13 Thread e-mail ma015k3113 via R-help
Dear All,I have a dataframe with 4 variables and I am trying to calculate how many shares can be purchased with £100 in the first year when the company was listed The data looks like: COMPANY_NUMBER YEAR_END_DATE CLOSE_SHARE_PRICE NUMBER_OF_SHARES 22705

[R] Add a new row based on test set predicted values and time stamps

2021-04-13 Thread Elahe chalabi via R-help
Hi all, I have the prediction for my test set which are forecasted Value for "4/1/2020" for each match of "id" and "Group". I would like to add a fourth row to each group by (Group,id) in my train set and the values for this row should come from test set : my train set:       

Re: [R] LHS random number generator

2021-04-13 Thread Shah Alam
Hi Richard and Jim Thanks for your response. Sorry for the confusion. This is lhs package (small letters), and after loading the package, I used the function randomLHS. The problem remained the same. I am trying to fix the length.out=2 for lmp=c(0.40, 0.43), and length.out = 4 for all other

[R] install_github does not work locally

2021-04-13 Thread Federico Calboli
Hello, I am trying to install a package from github, but my local installation fails (whereas doing the very same thing on a remote cluster works, and downloading the tarball by hand works). I assume the issue is mine, but I have no idea how to solve it. In any case, here is what I am doing

Re: [R] LHS random number generator

2021-04-13 Thread Jim Lemon
Hi Shah, I think what you are struggling toward is this: prior_lhs <- list(r_mu=c( 0.00299, 0.0032), r_sd=c( 0.001, 0.002), lmp=c( 0.40, 0.43), gr_mu=c( 0.14, 0.16), gr_s=c( 0.01, 0.020), alpha1=c( 0.0001,

Re: [R] Weighted violin chart

2021-04-13 Thread Chris Evans
- Original Message - > From: "Mahmood Naderan-Tahan" > To: r-help@r-project.org > Sent: Monday, 12 April, 2021 21:01:18 > Subject: [R] Weighted violin chart > Hi, > > I would like to know if it is possible to plot a weighted violin chart with R. > Currently, I have > > >>