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, useRaster=TRUE)

... to look like.

I also wonder whether switching to ...

dx[1][rep(1, length(dx))]

... might be better than switching to ...

as.numeric(dx)

It produces the same result for "difftime" objects, and may have a 
better chance of working better with other objects (although I confess 
that not having thought of using a "difftime" for 'x' I am also failing 
to think of further possibilities for 'x').


Paul

On 14/04/21 3:11 am, cda...@posteo.de wrote:

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"), as.Date("2020-12-31"), l=12)
check_irregular(time, time)
# TRUE
```
In my view, this is not correct.

In this case, the `all.equal`-call does not evaluate to true due to the
special class of `dx` (or `dy`). If I slightly rewrite the function as
```
my_check_irregular <- function (x, y)
{
dx <- as.numeric(diff(x))
dy <- as.numeric(diff(y))
(length(dx) && !isTRUE(all.equal(dx, rep(dx[1], length(dx) ||
(length(dy) && !isTRUE(all.equal(dy, rep(dy[1], length(dy)
}
```
the correct answer is obtained (i.e. that the input vector is not
irregular based on the rational behind `all.equal`):
```
my_check_irregular(time, time)
# FALSE
```

The same applies to POSIX* objects. I was wondering if this is intended
or not?

Thanks a lot for any answer,
Chris
[[alternative HTML version deleted]]

__
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.R-project.org/posting-guide.html 


and provide commented, minimal, self-contained, reproducible code.


--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/

__
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.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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 <-with(test2, tapply(CLOSE_SHARE_PRICE, COMPANY_NUMBER,
+   FUN =function(x)100 /x[1]))
> out
 1091347 1135606922705 SC192761
12.28501 91.74312 15.26718 91.74312
## essentially a labelled vector
##You can use  %/% if you only want the whole number of shares that can be
purchased

It's somewhat messier if the results are not ordered by date within company
-- you could use by() and POSIXct to order the dates within company to get
the right one.

Cheers,

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, Apr 13, 2021 at 11:34 AM e-mail ma015k3113 via R-help <
r-help@r-project.org> wrote:

> 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 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] = 100/is.na(CLOSE_SHARE_PRICE[i])
> >}
> > }
> >
> >
> > Hope this helps,
> >
> > Rui Barradas
> >
> > Às 13:51 de 13/04/21, e-mail ma015k3113 via R-help escreveu:
> > > 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
> > > 2270530/09/2002
>   NA 0
> > > 2270530/09/2004
>  NA  0
> > > 2270530/09/2005
> 6.55 0
> > > 2270530/09/2006
> 7.5   0
> > > 2270530/09/2007
> 9.65 0
> > > 2270530/09/2008
> 6.55 0
> > > 109134731/01/2010
> 8.14 0
> > > 1091347 31/01/2011
> 11.38 0
> > > 11356069   30/06/2019
> 1.09   0
> > > SC192761 31/01/2000
>  NA   0
> > > SC192761 31/01/2001
>  NA   0
> > > SC192761  31/01/2002
> NA   0
> > > SC192761 31/01/2004
>  NA   0
> > > SC192761 31/01/2005
>  NA   0
> > > SC192761  31/01/2006
> 1.09   0
> > > SC192761  31/01/2008
> 1.24   0
> > > SC192761  31/01/2009
>  0.90
> > > SC192761  31/01/2010 1.14
>   0
> > > SC192761   31/01/20111.25
>   0
> > > SC192761  31/01/2012 1.29
>   0
> > >
> > >
> > > The code I have written is
> > >
> > > i <- 0
> > >
> > > 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] = 100/is.na(CLOSE_SHARE_PRICE[i])
> > > }
> > >
> > >
> > > The error I get is Error: unexpected 'else' in:
> > >
> > > " NUMBER_OF_SHARES[i] = 0
> > > } else"
> > >> {NUMBER_OF_SHARES[i] = 100/is.na(CLOSE_SHARE_PRICE[i])}
> > >>
> > >> }
> > > Error: unexpected '}' in "}"
> > >
> > >
> > > Don't know how to fix it-any help will be appreciated.
> > >
> > >
> > > Kind regards
> > >
> > >
> > > Ahson
> > > [[alternative HTML version deleted]]
> > >
> > > __
> > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > https://stat.ethz.ch/mailman/listinfo/r-

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 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] = 100/is.na(CLOSE_SHARE_PRICE[i])
>}
> }
> 
> 
> Hope this helps,
> 
> Rui Barradas
> 
> Às 13:51 de 13/04/21, e-mail ma015k3113 via R-help escreveu:
> > 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
> > 2270530/09/2002  NA 
> > 0
> > 2270530/09/2004 NA  
> > 0
> > 2270530/09/20056.55 
> > 0
> > 2270530/09/20067.5  
> >  0
> > 2270530/09/20079.65 
> > 0
> > 2270530/09/20086.55 
> > 0
> > 109134731/01/20108.14   
> >   0
> > 1091347 31/01/2011  11.38   
> >   0
> > 11356069   30/06/2019  1.09 
> >   0
> > SC192761 31/01/2000 NA  
> >  0
> > SC192761 31/01/2001 NA  
> >  0
> > SC192761  31/01/2002NA  
> >  0
> > SC192761 31/01/2004 NA  
> >  0
> > SC192761 31/01/2005 NA  
> >  0
> > SC192761  31/01/2006  1.09  
> >  0
> > SC192761  31/01/2008  1.24  
> >  0
> > SC192761  31/01/2009   0.9  
> >   0
> > SC192761  31/01/2010 1.14   
> >  0
> > SC192761   31/01/20111.25   
> >  0
> > SC192761  31/01/2012 1.29   
> >  0
> > 
> > 
> > The code I have written is
> > 
> > i <- 0
> > 
> > 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] = 100/is.na(CLOSE_SHARE_PRICE[i])
> > }
> > 
> > 
> > The error I get is Error: unexpected 'else' in:
> > 
> > " NUMBER_OF_SHARES[i] = 0
> > } else"
> >> {NUMBER_OF_SHARES[i] = 100/is.na(CLOSE_SHARE_PRICE[i])}
> >>
> >> }
> > Error: unexpected '}' in "}"
> > 
> > 
> > Don't know how to fix it-any help will be appreciated.
> > 
> > 
> > Kind regards
> > 
> > 
> > Ahson
> > [[alternative HTML version deleted]]
> > 
> > __
> > 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.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >

__
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.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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, units="days" ) ) 
unless you are using GMT.

On April 13, 2021 10:55:04 AM PDT, Bert Gunter  wrote:
>(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 it."
>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
>On Tue, Apr 13, 2021 at 10:47 AM Bert Gunter 
>wrote:
>
>> 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 do is:
>>
>> ## with train and test your train and test data frames of course
>> out <- na.omit(rbind(train, cbind(test[,c(1,3,4)], Value =
>> test[,"value"])))
>> ## Note that the cbind() stuff is needed to create the correct
>"Value"
>> column for rbind(). See ?rbind for details
>>
>> If you insist that you need the row ordering as you specified, then
>follow
>> this by:
>>
>> out <- with(out, out[order(Group, id, as.POSIXct(Date,format =
>"%D%")), ])
>>
>> What this does is to first convert your text data column to POSIXct
>("See
>> ?DateTimeClasses for details) which gives them the desired calendar
>> ordering. The order() function (see ?order for details) then gives
>the
>> permutation ordering them from early to late within groups and id's,
>which
>> are then used as the row subscripts to reorder the rows in the data
>frame.
>>
>> DO NOTE: For this to work reliably, your Date column must be
>consistent
>> and correct in its formatting!
>>
>> Other note: It probably makes more sense to convert your Date column
>to a
>> POSIXct or POSIXlt dates from the beginning, as this will make things
>like
>> plotting in date order straightforward. There are also date-time
>packages
>> (in the "tidyverse" suite, I think,  as well as others) that simplify
>such
>> things. I am pretty ignorant about date-time stuff, so I can't really
>be
>> more specific. https://cran.r-project.org/web/views/TimeSeries.html 
>will
>> have lots of info on this if you need it. As well as searching, of
>course.
>>
>> HTH
>>
>> Bert Gunter
>>
>> "The trouble with having an open mind is that people keep coming
>along and
>> sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>>
>> On Tue, Apr 13, 2021 at 3:26 AM Elahe chalabi via R-help <
>> r-help@r-project.org> wrote:
>>
>>> 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:
>>>
>>>  structure(list(Date = c("1/1/2020", "2/1/2020", "3/1/2020",
>>> "1/1/2020",
>>>  "2/1/2020", "3/1/2020", "1/1/2020", "2/1/2020", "3/1/2020", ""
>>>  ), Value = c(3.5, 2.7, 4, 2.5, 3.7, 0, 3, 0, 1, NA), Group =
>c("A",
>>> "A", "A", "B", "B", "B", "C", "C", "C", ""), id = c(1L, 1L, 1L,
>>> 101L, 101L, 101L, 100L, 100L, 100L, NA)), class = "data.frame",
>>> row.names = c(NA,
>>> -10L))
>>>
>>> test set:
>>>
>>> structure(list(Date = c("4/1/2020", "4/1/2020", "4/1/2020", ""
>>>   ), Value = c(3.5, 2.5, 3, NA), Group = c("A", "B", "C", ""),
>>> id = c(1L, 101L, 100L, NA), value = c(0.2, 0.7, 0.9, NA)), class
>=
>>> "data.frame", row.names = c(NA,
>>>  -4L))structure(list(Date = c("4/1/2020", "4/1/2020",
>"4/1/2020", ""
>>> ), Value = c(3.5, 2.5, 3, NA), Group = c("A", "B", "C", ""),
>>> id = c(1L, 101L, 100L, NA)), class = "data.frame", row.names =
>c(NA,
>>> -4L))
>>>
>>> desired output:
>>>
>>> structure(list(Date = c("1/1/2020", "2/1/2020", "3/1/2020",
>>> "4/1/2020",
>>> "1/1/2020", "2/1/2020", "3/1/2020", "4/1/2020", "1/1/2020",
>>> "2/1/2020",
>>> "3/1/2020", "4/1/2020"), Value = c(3.5, 2.7, 4, 0.2, 2.5, 3.7,
>>>  0, 0.7, 3, 0, 1, 0.9), Group = c("A", "A", "A", "A", "B", "B",
>>> "B", "B", "C", "C", "C", "C"), id = c(1L, 1L, 1L, 1L, 101L,
>101L,
>>> 101L, 101L, 100L, 100L, 100L, 100L)), class = "data.frame",
>row.names
>>> = c(NA,
>>>-12L))
>>>
>>> Data is dummy and I have milions of records in original data set.
>>>
>>> Thanks for any help.
>>> Elahe
>>>
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/m

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 it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, Apr 13, 2021 at 10:47 AM Bert Gunter  wrote:

> 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 do is:
>
> ## with train and test your train and test data frames of course
> out <- na.omit(rbind(train, cbind(test[,c(1,3,4)], Value =
> test[,"value"])))
> ## Note that the cbind() stuff is needed to create the correct "Value"
> column for rbind(). See ?rbind for details
>
> If you insist that you need the row ordering as you specified, then follow
> this by:
>
> out <- with(out, out[order(Group, id, as.POSIXct(Date,format = "%D%")), ])
>
> What this does is to first convert your text data column to POSIXct ("See
> ?DateTimeClasses for details) which gives them the desired calendar
> ordering. The order() function (see ?order for details) then gives the
> permutation ordering them from early to late within groups and id's, which
> are then used as the row subscripts to reorder the rows in the data frame.
>
> DO NOTE: For this to work reliably, your Date column must be consistent
> and correct in its formatting!
>
> Other note: It probably makes more sense to convert your Date column to a
> POSIXct or POSIXlt dates from the beginning, as this will make things like
> plotting in date order straightforward. There are also date-time packages
> (in the "tidyverse" suite, I think,  as well as others) that simplify such
> things. I am pretty ignorant about date-time stuff, so I can't really be
> more specific. https://cran.r-project.org/web/views/TimeSeries.html  will
> have lots of info on this if you need it. As well as searching, of course.
>
> HTH
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Tue, Apr 13, 2021 at 3:26 AM Elahe chalabi via R-help <
> r-help@r-project.org> wrote:
>
>> 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:
>>
>>  structure(list(Date = c("1/1/2020", "2/1/2020", "3/1/2020",
>> "1/1/2020",
>>  "2/1/2020", "3/1/2020", "1/1/2020", "2/1/2020", "3/1/2020", ""
>>  ), Value = c(3.5, 2.7, 4, 2.5, 3.7, 0, 3, 0, 1, NA), Group = c("A",
>> "A", "A", "B", "B", "B", "C", "C", "C", ""), id = c(1L, 1L, 1L,
>> 101L, 101L, 101L, 100L, 100L, 100L, NA)), class = "data.frame",
>> row.names = c(NA,
>> -10L))
>>
>> test set:
>>
>> structure(list(Date = c("4/1/2020", "4/1/2020", "4/1/2020", ""
>>   ), Value = c(3.5, 2.5, 3, NA), Group = c("A", "B", "C", ""),
>> id = c(1L, 101L, 100L, NA), value = c(0.2, 0.7, 0.9, NA)), class =
>> "data.frame", row.names = c(NA,
>>  -4L))structure(list(Date = c("4/1/2020", "4/1/2020", "4/1/2020", ""
>> ), Value = c(3.5, 2.5, 3, NA), Group = c("A", "B", "C", ""),
>> id = c(1L, 101L, 100L, NA)), class = "data.frame", row.names = c(NA,
>> -4L))
>>
>> desired output:
>>
>> structure(list(Date = c("1/1/2020", "2/1/2020", "3/1/2020",
>> "4/1/2020",
>> "1/1/2020", "2/1/2020", "3/1/2020", "4/1/2020", "1/1/2020",
>> "2/1/2020",
>> "3/1/2020", "4/1/2020"), Value = c(3.5, 2.7, 4, 0.2, 2.5, 3.7,
>>  0, 0.7, 3, 0, 1, 0.9), Group = c("A", "A", "A", "A", "B", "B",
>> "B", "B", "C", "C", "C", "C"), id = c(1L, 1L, 1L, 1L, 101L, 101L,
>> 101L, 101L, 100L, 100L, 100L, 100L)), class = "data.frame", row.names
>> = c(NA,
>>-12L))
>>
>> Data is dummy and I have milions of records in original data set.
>>
>> Thanks for any help.
>> Elahe
>>
>>
>> __
>> 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.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>

[[alternative HTML version deleted]]

__
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.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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 do is:

## with train and test your train and test data frames of course
out <- na.omit(rbind(train, cbind(test[,c(1,3,4)], Value = test[,"value"])))
## Note that the cbind() stuff is needed to create the correct "Value"
column for rbind(). See ?rbind for details

If you insist that you need the row ordering as you specified, then follow
this by:

out <- with(out, out[order(Group, id, as.POSIXct(Date,format = "%D%")), ])

What this does is to first convert your text data column to POSIXct ("See
?DateTimeClasses for details) which gives them the desired calendar
ordering. The order() function (see ?order for details) then gives the
permutation ordering them from early to late within groups and id's, which
are then used as the row subscripts to reorder the rows in the data frame.

DO NOTE: For this to work reliably, your Date column must be consistent and
correct in its formatting!

Other note: It probably makes more sense to convert your Date column to a
POSIXct or POSIXlt dates from the beginning, as this will make things like
plotting in date order straightforward. There are also date-time packages
(in the "tidyverse" suite, I think,  as well as others) that simplify such
things. I am pretty ignorant about date-time stuff, so I can't really be
more specific. https://cran.r-project.org/web/views/TimeSeries.html  will
have lots of info on this if you need it. As well as searching, of course.

HTH

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, Apr 13, 2021 at 3:26 AM Elahe chalabi via R-help <
r-help@r-project.org> wrote:

> 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:
>
>  structure(list(Date = c("1/1/2020", "2/1/2020", "3/1/2020",
> "1/1/2020",
>  "2/1/2020", "3/1/2020", "1/1/2020", "2/1/2020", "3/1/2020", ""
>  ), Value = c(3.5, 2.7, 4, 2.5, 3.7, 0, 3, 0, 1, NA), Group = c("A",
> "A", "A", "B", "B", "B", "C", "C", "C", ""), id = c(1L, 1L, 1L,
> 101L, 101L, 101L, 100L, 100L, 100L, NA)), class = "data.frame",
> row.names = c(NA,
> -10L))
>
> test set:
>
> structure(list(Date = c("4/1/2020", "4/1/2020", "4/1/2020", ""
>   ), Value = c(3.5, 2.5, 3, NA), Group = c("A", "B", "C", ""),
> id = c(1L, 101L, 100L, NA), value = c(0.2, 0.7, 0.9, NA)), class =
> "data.frame", row.names = c(NA,
>  -4L))structure(list(Date = c("4/1/2020", "4/1/2020", "4/1/2020", ""
> ), Value = c(3.5, 2.5, 3, NA), Group = c("A", "B", "C", ""),
> id = c(1L, 101L, 100L, NA)), class = "data.frame", row.names = c(NA,
> -4L))
>
> desired output:
>
> structure(list(Date = c("1/1/2020", "2/1/2020", "3/1/2020",
> "4/1/2020",
> "1/1/2020", "2/1/2020", "3/1/2020", "4/1/2020", "1/1/2020",
> "2/1/2020",
> "3/1/2020", "4/1/2020"), Value = c(3.5, 2.7, 4, 0.2, 2.5, 3.7,
>  0, 0.7, 3, 0, 1, 0.9), Group = c("A", "A", "A", "A", "B", "B",
> "B", "B", "C", "C", "C", "C"), id = c(1L, 1L, 1L, 1L, 101L, 101L,
> 101L, 101L, 100L, 100L, 100L, 100L)), class = "data.frame", row.names
> = c(NA,
>-12L))
>
> Data is dummy and I have milions of records in original data set.
>
> Thanks for any help.
> Elahe
>
>
> __
> 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.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
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.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[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"), as.Date("2020-12-31"), l=12)
 check_irregular(time, time)
# TRUE
```
In my view, this is not correct. 

In this case, the `all.equal`-call does not evaluate to true due to the
special class of `dx` (or `dy`). If I slightly rewrite the function as
```
my_check_irregular <- function (x, y)
{ 
 dx <- as.numeric(diff(x)) 
 dy <- as.numeric(diff(y)) 
 (length(dx) && !isTRUE(all.equal(dx, rep(dx[1], length(dx) || 
 (length(dy) && !isTRUE(all.equal(dy, rep(dy[1], length(dy) 
}
 ```
the correct answer is obtained (i.e. that the input vector is not
irregular based on the rational behind `all.equal`):
```
my_check_irregular(time, time) 
# FALSE
 ```

The same applies to POSIX* objects. I was wondering if this is intended
or not?

Thanks a lot for any answer,
Chris 
[[alternative HTML version deleted]]

__
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.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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 " }"
> }
Error: unexpected '}' in " }"
> }
Error: unexpected '}' in "}"
>

I have spent so much time on this-hopefully I will come to grips sooner or 
later. In the mean time any further suggestion?


Kind regards


Ahson

> On 13 April 2021 at 14:29 jim holtman  wrote:
> 
> 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 1:(nrow(PLC_Return) - 1)) {
>   if (i == 1) {
> NUMBER_OF_SHARES[i] = 100 /http://is.na (CLOSE_SHARE_PRICE[i])
>   } else {
> if (http://is.na (PLC_Return[i, 1]) ==http://is.na (PLC_Return[i + 1, 
> 1]) {
>   NUMBER_OF_SHARES[i] = 0
> } else {
>   NUMBER_OF_SHARES[i] = 100 /http://is.na (CLOSE_SHARE_PRICE[i])
> }
>   }
> }  
> 
> 
> Jim Holtman
> Data Munger Guru
>  
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
> 
> 
> On Tue, Apr 13, 2021 at 5:51 AM e-mail ma015k3113 via R-help < 
> r-help@r-project.org mailto:r-help@r-project.org > wrote:
> 
> > > 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
> > 2270530/09/2002 
> >  NA 0
> > 2270530/09/2004 
> > NA  0
> > 2270530/09/2005 
> >6.55 0
> > 2270530/09/2006 
> >7.5   0
> > 2270530/09/2007 
> >9.65 0
> > 2270530/09/2008 
> >6.55 0
> > 109134731/01/2010   
> >  8.14 0
> > 1091347 31/01/2011  
> > 11.38 0
> > 11356069   30/06/2019  
> > 1.09   0
> > SC192761 31/01/2000 
> > NA   0
> > SC192761 31/01/2001 
> > NA   0
> > SC192761  31/01/2002
> > NA   0
> > SC192761 31/01/2004 
> > NA   0
> > SC192761 31/01/2005 
> > NA   0
> > SC192761  31/01/2006  
> > 1.09   0
> > SC192761  31/01/2008  
> > 1.24   0
> > SC192761  31/01/2009   
> > 0.90
> > SC192761  31/01/2010 
> > 1.140
> > SC192761   31/01/2011
> > 1.250
> > SC192761  31/01/2012 
> > 1.290
> > 
> > 
> > The code I have written is
> > 
> > i <- 0
> > 
> > for (i in 1:(nrow(PLC_Return)-1))
> > if (i == 1)
> > {
> > NUMBER_OF_SHARES[i] = 100/http://is.na (CLOSE_SHARE_PRICE[i])
> > } else if
> > (http://is.na (PLC_Return[i, 1]) ==http://is.na (PLC_Return[i + 1, 
> > 1])
> > {
> > NUMBER_OF_SHARES[i]=0
> > } else
> > {
> > NUMBER_OF_SHARES[i] = 100/http://is.na (CLOSE_SHARE_PRICE[i])
> > }
> > 
> > 
> > The error I get is Error: unexpected 'else' 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 if(is.na(PLC_Return[i, 1]) == is.na(PLC_Return[i + 1, 1])){
     NUMBER_OF_SHARES[i]=0
   } else {
     NUMBER_OF_SHARES[i] = 100/is.na(CLOSE_SHARE_PRICE[i])
   }
}


Hope this helps,

Rui Barradas

Às 13:51 de 13/04/21, e-mail ma015k3113 via R-help escreveu:
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
30/09/2002  NA 0
22705
30/09/2004 NA  0
22705    30/09/2005
6.55 0
22705    30/09/2006
7.5   0
22705    30/09/2007
9.65 0
22705    30/09/2008
6.55 0
1091347    31/01/2010
8.14 0
1091347 31/01/2011  
11.38 0
11356069   30/06/2019  
1.09   0
SC192761 31/01/2000 
NA   0
SC192761 31/01/2001 
NA   0
SC192761  31/01/2002
NA   0
SC192761 31/01/2004 
NA   0
SC192761 31/01/2005 
NA   0
SC192761  31/01/2006  
1.09   0
SC192761  31/01/2008  
1.24   0
SC192761  31/01/2009   
0.9    0
SC192761  31/01/2010 
1.14    0
SC192761   31/01/2011
1.25    0
SC192761  31/01/2012 
1.29    0



The code I have written is

i <- 0

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] = 100/is.na(CLOSE_SHARE_PRICE[i])
}


The error I get is Error: unexpected 'else' in:

" NUMBER_OF_SHARES[i] = 0
} else"

{NUMBER_OF_SHARES[i] = 100/is.na(CLOSE_SHARE_PRICE[i])}

}

Error: unexpected '}' in "}"


Don't know how to fix it-any help will be appreciated.


Kind regards


Ahson
[[alternative HTML version deleted]]

__
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.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.



__
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.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


__
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.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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] = 100/is.na(CLOSE_SHARE_PRICE[i])
  }
}


Hope this helps,

Rui Barradas

Às 13:51 de 13/04/21, e-mail ma015k3113 via R-help escreveu:

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
2270530/09/2002  NA 
0
2270530/09/2004 NA  
0
2270530/09/20056.55 
0
2270530/09/20067.5  
 0
2270530/09/20079.65 
0
2270530/09/20086.55 
0
109134731/01/20108.14   
  0
1091347 31/01/2011  11.38   
  0
11356069   30/06/2019  1.09 
  0
SC192761 31/01/2000 NA  
 0
SC192761 31/01/2001 NA  
 0
SC192761  31/01/2002NA  
 0
SC192761 31/01/2004 NA  
 0
SC192761 31/01/2005 NA  
 0
SC192761  31/01/2006  1.09  
 0
SC192761  31/01/2008  1.24  
 0
SC192761  31/01/2009   0.9  
  0
SC192761  31/01/2010 1.14   
 0
SC192761   31/01/20111.25   
 0
SC192761  31/01/2012 1.29   
 0


The code I have written is

i <- 0

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] = 100/is.na(CLOSE_SHARE_PRICE[i])
}


The error I get is Error: unexpected 'else' in:

" NUMBER_OF_SHARES[i] = 0
} else"

{NUMBER_OF_SHARES[i] = 100/is.na(CLOSE_SHARE_PRICE[i])}

}

Error: unexpected '}' in "}"


Don't know how to fix it-any help will be appreciated.


Kind regards


Ahson
[[alternative HTML version deleted]]

__
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.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
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.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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 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] = 100 / is.na(CLOSE_SHARE_PRICE[i])
}
  }
}


Jim Holtman
*Data Munger Guru*


*What is the problem that you are trying to solve?Tell me what you want to
do, not how you want to do it.*


On Tue, Apr 13, 2021 at 5:51 AM e-mail ma015k3113 via R-help <
r-help@r-project.org> wrote:

> 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
> 2270530/09/2002
> NA 0
> 2270530/09/2004
>  NA  0
> 2270530/09/2005
> 6.55 0
> 2270530/09/2006
> 7.5   0
> 2270530/09/2007
> 9.65 0
> 2270530/09/2008
> 6.55 0
> 109134731/01/20108.14
>0
> 1091347 31/01/2011  11.38
>0
> 11356069   30/06/2019  1.09
>0
> SC192761 31/01/2000 NA
>0
> SC192761 31/01/2001 NA
>0
> SC192761  31/01/2002NA
>0
> SC192761 31/01/2004 NA
>0
> SC192761 31/01/2005 NA
>0
> SC192761  31/01/2006  1.09
>0
> SC192761  31/01/2008  1.24
>0
> SC192761  31/01/2009   0.9
> 0
> SC192761  31/01/2010 1.14
>   0
> SC192761   31/01/20111.25
>   0
> SC192761  31/01/2012 1.29
>   0
>
>
> The code I have written is
>
> i <- 0
>
> 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] = 100/is.na(CLOSE_SHARE_PRICE[i])
> }
>
>
> The error I get is Error: unexpected 'else' in:
>
> " NUMBER_OF_SHARES[i] = 0
> } else"
> > {NUMBER_OF_SHARES[i] = 100/is.na(CLOSE_SHARE_PRICE[i])}
> >
> > }
> Error: unexpected '}' in "}"
>
>
> Don't know how to fix it-any help will be appreciated.
>
>
> Kind regards
>
>
> Ahson
> [[alternative HTML version deleted]]
>
> __
> 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.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
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.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[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
2270530/09/2002  NA 
0
2270530/09/2004 NA  
0
2270530/09/20056.55 
0
2270530/09/20067.5  
 0
2270530/09/20079.65 
0
2270530/09/20086.55 
0
109134731/01/20108.14   
  0
1091347 31/01/2011  11.38   
  0
11356069   30/06/2019  1.09 
  0
SC192761 31/01/2000 NA  
 0
SC192761 31/01/2001 NA  
 0
SC192761  31/01/2002NA  
 0
SC192761 31/01/2004 NA  
 0
SC192761 31/01/2005 NA  
 0
SC192761  31/01/2006  1.09  
 0
SC192761  31/01/2008  1.24  
 0
SC192761  31/01/2009   0.9  
  0
SC192761  31/01/2010 1.14   
 0
SC192761   31/01/20111.25   
 0
SC192761  31/01/2012 1.29   
 0


The code I have written is

i <- 0

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] = 100/is.na(CLOSE_SHARE_PRICE[i])
}


The error I get is Error: unexpected 'else' in:

" NUMBER_OF_SHARES[i] = 0
} else"
> {NUMBER_OF_SHARES[i] = 100/is.na(CLOSE_SHARE_PRICE[i])}
>
> }
Error: unexpected '}' in "}"


Don't know how to fix it-any help will be appreciated.


Kind regards


Ahson
[[alternative HTML version deleted]]

__
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.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[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: 

     structure(list(Date = c("1/1/2020", "2/1/2020", "3/1/2020", "1/1/2020", 
     "2/1/2020", "3/1/2020", "1/1/2020", "2/1/2020", "3/1/2020", ""
     ), Value = c(3.5, 2.7, 4, 2.5, 3.7, 0, 3, 0, 1, NA), Group = c("A", 
    "A", "A", "B", "B", "B", "C", "C", "C", ""), id = c(1L, 1L, 1L, 
    101L, 101L, 101L, 100L, 100L, 100L, NA)), class = "data.frame", row.names = 
c(NA, 
    -10L))

test set:

    structure(list(Date = c("4/1/2020", "4/1/2020", "4/1/2020", ""
      ), Value = c(3.5, 2.5, 3, NA), Group = c("A", "B", "C", ""), 
    id = c(1L, 101L, 100L, NA), value = c(0.2, 0.7, 0.9, NA)), class = 
"data.frame", row.names = c(NA, 
     -4L))structure(list(Date = c("4/1/2020", "4/1/2020", "4/1/2020", ""
    ), Value = c(3.5, 2.5, 3, NA), Group = c("A", "B", "C", ""), 
    id = c(1L, 101L, 100L, NA)), class = "data.frame", row.names = c(NA, 
    -4L))

desired output: 

    structure(list(Date = c("1/1/2020", "2/1/2020", "3/1/2020", "4/1/2020", 
    "1/1/2020", "2/1/2020", "3/1/2020", "4/1/2020", "1/1/2020", "2/1/2020", 
    "3/1/2020", "4/1/2020"), Value = c(3.5, 2.7, 4, 0.2, 2.5, 3.7, 
     0, 0.7, 3, 0, 1, 0.9), Group = c("A", "A", "A", "A", "B", "B", 
    "B", "B", "C", "C", "C", "C"), id = c(1L, 1L, 1L, 1L, 101L, 101L, 
    101L, 101L, 100L, 100L, 100L, 100L)), class = "data.frame", row.names = 
c(NA, 
   -12L))

Data is dummy and I have milions of records in original data set. 

Thanks for any help.
Elahe 
 

__
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.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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 variables/inputs.

Best regards,
Shah








On Tue, 13 Apr 2021 at 09:02, Jim Lemon  wrote:

> 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, 0.0018),
>   alpha2=c(0.0017, 0.0028),
>   alpha3=c( 0.005, 0.009),
>   beta=c(0.69, 0.75))
> for(i in 1:length(prior_lhs))
>  prior_lhs[[i]]<-seq(prior_lhs[[i]][1],prior_lhs[[i]][2],length.out=4)
>
> This gives you the "quartiles" you need for randomLHS function in the
> "lhs" package if I read the help page correctly.
>
> Jim
>
> On Mon, Apr 12, 2021 at 10:21 PM Shah Alam 
> wrote:
> >
> > Hello everyone,
> >
> > I am using the LHS package to generate a combination of a
> > set of parameter values. However, I am not sure how to fix some parameter
> > values to 2 decimal points.
> > For example:
> >
> > I want to make combinations in such a way that values for parameter
> > c("lmp", 0.40, 0.43) are taken as 0.40, 0.41, 0.42,0.43.
> >
> > My codes are:
> >
> > prior_lhs <- list(c("r_mu", 0.00299, 0.0032),
> >   c("r_sd", 0.001, 0.002),
> >   c("lmp", 0.40, 0.43),
> >   c("gr_mu", 0.14, 0.16),
> >   c("gr_sd", 0.01, 0.020),
> >   c("alpha1", 0.0001, 0.0018),
> >   c("alpha2", 0.0017, 0.0028),
> >   c("alpha3", 0.005, 0.009),
> >   c("beta", 0.69, 0.75)
> > )
> >
> >
> > ### Simulation with priors from LHS 
> > nb_simul <- 1
> > nparam <- length(prior_lhs)
> > random_tab = randomLHS(nb_simul, nparam)
> > lhs_index = 1
> > param <- matrix(rep(0, nparam), nrow = 1, ncol = nparam)
> >
> > for (i in 1:nb_simul) {
> >   temp_par <- matrix(rep(0, nparam), nrow = 1, ncol = nparam)
> >   for (j in 1:nparam) {
> > temp_par[j] = as.numeric(prior_lhs[[j]][2]) +
> >   (as.numeric(prior_lhs[[j]][3]) - as.numeric(prior_lhs[[j]][2])) *
> > random_tab[lhs_index, j]
> >   }
> >   param <- rbind(param, temp_par)
> >   lhs_index <- lhs_index+1
> > }
> > param <- param[-1,]
> >
> > Best regards,
> > Shah
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > 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.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
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.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[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 and my session info.

Cheers

F

devtools::install_github("Syksy/curatedPCaData")
Downloading GitHub repo Syksy/curatedPCaData@HEAD
Error in utils::download.file(url, path, method = method, quiet = quiet,  : 
  download from 
'https://api.github.com/repos/Syksy/curatedPCaData/tarball/HEAD’ failed


> sessionInfo()
R version 4.0.4 (2021-02-15)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   
/Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: 
/Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 

loaded via a namespace (and not attached):
 [1] magrittr_2.0.1usethis_2.0.1 devtools_2.4.0pkgload_1.2.1 
R6_2.5.0  rlang_0.4.10  fastmap_1.1.0 tools_4.0.4  
 [9] pkgbuild_1.2.0sessioninfo_1.1.1 cli_2.4.0 withr_2.4.1   
ellipsis_0.3.1remotes_2.3.0 rprojroot_2.0.2   lifecycle_1.0.0  
[17] crayon_1.4.1  processx_3.5.1purrr_0.3.4   callr_3.6.0   
fs_1.5.0  ps_1.6.0  curl_4.3  testthat_3.0.2   
[25] memoise_2.0.0 glue_1.4.2cachem_1.0.4  compiler_4.0.4
desc_1.3.0prettyunits_1.1.1

--
Federico Calboli
LBEG - Laboratory of Biodiversity and Evolutionary Genomics
Charles Deberiotstraat 32 box 2439
3000 Leuven
+32 16 32 87 67





__
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.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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, 0.0018),
  alpha2=c(0.0017, 0.0028),
  alpha3=c( 0.005, 0.009),
  beta=c(0.69, 0.75))
for(i in 1:length(prior_lhs))
 prior_lhs[[i]]<-seq(prior_lhs[[i]][1],prior_lhs[[i]][2],length.out=4)

This gives you the "quartiles" you need for randomLHS function in the
"lhs" package if I read the help page correctly.

Jim

On Mon, Apr 12, 2021 at 10:21 PM Shah Alam  wrote:
>
> Hello everyone,
>
> I am using the LHS package to generate a combination of a
> set of parameter values. However, I am not sure how to fix some parameter
> values to 2 decimal points.
> For example:
>
> I want to make combinations in such a way that values for parameter
> c("lmp", 0.40, 0.43) are taken as 0.40, 0.41, 0.42,0.43.
>
> My codes are:
>
> prior_lhs <- list(c("r_mu", 0.00299, 0.0032),
>   c("r_sd", 0.001, 0.002),
>   c("lmp", 0.40, 0.43),
>   c("gr_mu", 0.14, 0.16),
>   c("gr_sd", 0.01, 0.020),
>   c("alpha1", 0.0001, 0.0018),
>   c("alpha2", 0.0017, 0.0028),
>   c("alpha3", 0.005, 0.009),
>   c("beta", 0.69, 0.75)
> )
>
>
> ### Simulation with priors from LHS 
> nb_simul <- 1
> nparam <- length(prior_lhs)
> random_tab = randomLHS(nb_simul, nparam)
> lhs_index = 1
> param <- matrix(rep(0, nparam), nrow = 1, ncol = nparam)
>
> for (i in 1:nb_simul) {
>   temp_par <- matrix(rep(0, nparam), nrow = 1, ncol = nparam)
>   for (j in 1:nparam) {
> temp_par[j] = as.numeric(prior_lhs[[j]][2]) +
>   (as.numeric(prior_lhs[[j]][3]) - as.numeric(prior_lhs[[j]][2])) *
> random_tab[lhs_index, j]
>   }
>   param <- rbind(param, temp_par)
>   lhs_index <- lhs_index+1
> }
> param <- param[-1,]
>
> Best regards,
> Shah
>
> [[alternative HTML version deleted]]
>
> __
> 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.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
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.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.