Re: [R] Off topic --- underdispersed (pseudo) binomial data.

2021-03-24 Thread Rolf Turner


On Wed, 24 Mar 2021 18:45:01 -0700
 wrote:

> "X = {X_1, X_2, ..., X_N} where each X_i
> is an integer between 0 and n (n known a priori)"
> 
> That is a multinomial, not a binomial distribution. A binomial
> distribution can have only two values, success or failure.
> 
> What have I misunderstood?

And then, following up:

> Oh, I think I get what you mean -- you are drawing repeated samples
> from a binomial with n trials and you are counting the number of
> successes for each.

Yes.  Exactly.  Sorry if my post was unclear.

cheers,

Rolf Turner

-- 
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] setting wd to parent directory ("..") of rmd file for all chunks of .Rmd

2021-03-24 Thread nevil amos
The Rmarkdown cookbook states that the working directory for r chunks in an
Rmd file is usually the directory containing the file,
 however it can be reset using

knitr::opts_knit$set(root.dir =

see:
https://bookdown.org/yihui/rmarkdown-cookbook/working-directory.html#working-directory
I want to set the directory to the parent direcotry of the default directory
usually I would acheive this using  setwd("..") so  in the rmd I used the
following:

```{r setup, include=FALSE,}
print(getwd())
knitr::opts_knit$set(root.dir = '..')
print(getwd())
```
the  print(getwd()) being just to demonstrate the result.  There is no
change in the directory.
How do I change the working directory ?

thanks

nevil Amos

[[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] Including a ggplot call with a conditional geom in a function

2021-03-24 Thread Avi Gross via R-help
This may not be the right place to ask about ggplot which is part of
packages but are you aware how ggplot works additively?

You can say something like:

P <- ggplot(...) ... + ...

Then later say:

P <- p + geom_...()

And so on.

So if you set al the layers you want first into a variable like p, then in
an if statement you selectively add in one or another layer and finally add
in all remaining layers before printing it, would that simply meet your
need?

Realistically, ggplot creates a data structure and the PLUS of other layers
updates or expands that structure but nothing happens till you print it and
it evaluates the data structure.

-Original Message-
From: R-help  On Behalf Of p...@philipsmith.ca
Sent: Wednesday, March 24, 2021 10:24 PM
To: r-help@r-project.org
Subject: [R] Including a ggplot call with a conditional geom in a function

How can I write an R function that contains a call to ggplot within it, with
one of the ggplot geom statements being conditional? In my reprex, I want
the plot to contain a horizontal zero line if the y values are both positive
and negative, and to exclude the horizontal line if all of the y values are
of the same sign. I tried a simple if statement, but it does not work.
Suggestions appreciated. Philip

library(rlang)
library(tidyverse)

a <- c(1:8)
b <- c(23,34,45,43,32,45,68,78)
c <- c(0.34,0.56,0.97,0.33,-0.23,-0.36,-0.11,0.17)
df <- data.frame(a,b,c)

posNeg <- function(x) {
   ifelse(sum(x>0)>0 & sum(x>0)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] Including a ggplot call with a conditional geom in a function

2021-03-24 Thread phil
How can I write an R function that contains a call to ggplot within it, 
with one of the ggplot geom statements being conditional? In my reprex, 
I want the plot to contain a horizontal zero line if the y values are 
both positive and negative, and to exclude the horizontal line if all of 
the y values are of the same sign. I tried a simple if statement, but it 
does not work. Suggestions appreciated. Philip


library(rlang)
library(tidyverse)

a <- c(1:8)
b <- c(23,34,45,43,32,45,68,78)
c <- c(0.34,0.56,0.97,0.33,-0.23,-0.36,-0.11,0.17)
df <- data.frame(a,b,c)

posNeg <- function(x) {
  ifelse(sum(x>0)>0 & sum(x>0)#if(posNeg({{MYy}})) geom_hline(yintercept=0,size=0.2)+   # This 
does not work

geom_line(colour="black",size=0.5)
}
(plot1 <- plotLineFunc(df,a,b))
(plot2 <- plotLineFunc(df,a,c))

__
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] Converting POSIXct format date to Character format

2021-03-24 Thread Jim Lemon
Hi ma015k3113,
I suspect that you are asking the wrong question.

# create an example data frame with an extra field
PLC<-read.table(text="YEAR_END_Date EPS   junk
2010-09-10.10 A
2009-08-10.20 B",
header=TRUE,
stringsAsFactors=FALSE)
# first, I think that you may already have the date in character format
# if you get this result, you don't need to convert it
sapply(PLC,"class")
YEAR_END_Date   EPS  junk
 "character" "numeric"   "character"
# however, if you get this result
sapply(PLC,"class")
$YEAR_END_Date
[1] "POSIXlt" "POSIXt"

$EPS
[1] "numeric"

$junk
[1] "character"
# then you do have a POSIX date in the first field,
# so you can do this:
PLC$YEAR_END_Date<-format(PLC$YEAR_END_Date,format="%Y-%m-%d")
# then if you want to select those two fields for further processing
# use this expression
PLC[,c("YEAR_END_Date","EPS")]

Jim

On Thu, Mar 25, 2021 at 6:11 AM e-mail ma015k3113 via R-help
 wrote:
>
> I have a data frame "PLC" which has two variables Year_END_Date   EPS
>
> YEAR_END_Date EPS
> 2010-09-10.10
> 2009-08-10.20
>
> When I tried to convert Year_END_Date to character format using
>
> select(PLC, format(Year_END_Date,format = "%B %d, %Y"), EPS) I get an error
>
> Error: Can't subset columns that don't exist.
> x Column `Year_END_Date` doesn't exist.
>
> I tried using
>
> PLC_1 <- select(PLC, as.character(YEAR_END_DATE), EPS)
>
> I get the following error
>
> Error: Can't subset columns that don't exist.
> x Columns `2010-09-30`, `2009-09-30`, `2008-09-30`, `2007-09-30`, 
> `2006-09-30`, etc. don't exist.
> Run `rlang::last_error()` to see where the error occurred.
>
> Can anyone please guide me what is happening and how can I resolve it?
>
> __
> 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] Converting POSIXct format date to Character format

2021-03-24 Thread Bert Gunter
What package is select() in?

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 Wed, Mar 24, 2021 at 4:42 PM Jeff Newmiller 
wrote:

> Please don't reply to a thread to start a new question... create a new
> email to avoid linking your question with the one you replied to.
>
> On March 24, 2021 12:11:07 PM PDT, e-mail ma015k3113 via R-help <
> r-help@r-project.org> wrote:
> >I have a data frame "PLC" which has two variables Year_END_Date   EPS
> >
> >YEAR_END_Date EPS
> >2010-09-10.10
> >2009-08-10.20
> >
> >When I tried to convert Year_END_Date to character format using
> >
> >select(PLC, format(Year_END_Date,format = "%B %d, %Y"), EPS) I get an
> >error
> >
> >Error: Can't subset columns that don't exist.
> >x Column `Year_END_Date` doesn't exist.
> >
> >I tried using
> >
> >PLC_1 <- select(PLC, as.character(YEAR_END_DATE), EPS)
> >
> >I get the following error
> >
> >Error: Can't subset columns that don't exist.
> >x Columns `2010-09-30`, `2009-09-30`, `2008-09-30`, `2007-09-30`,
> >`2006-09-30`, etc. don't exist.
> >Run `rlang::last_error()` to see where the error occurred.
> >
> >Can anyone please guide me what is happening and how can I resolve it?
> >
> >__
> >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.
>
> --
> Sent from my phone. Please excuse my brevity.
>
> __
> 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] Off topic --- underdispersed (pseudo) binomial data.

2021-03-24 Thread Rolf Turner


I would like a real-life example of a data set which one might think to
model by a binomial distribution, but which is substantially
underdispersed. I.e. a sample X = {X_1, X_2, ..., X_N} where each X_i
is an integer between 0 and n (n known a priori) such that var(X) <<
mean(X)*(1 - mean(X)/n).

Does anyone know of any such examples?  Do any exist?  I've done
a perfunctory web search, and had a look at "A Handbook of Small
Data Sets" by Hand, Daly, Lunn, et al., and drawn a blank.

I've seen on the web some references to underdispersed "pseudo-Poisson"
data, but not to underdispersed "pseudo-binomial" data.  And of course
there's lots of *over* dispersed stuff.  But that's not what I want.

I can *simulate* data sets of the sor that I am looking for (so far the
only ideas I've had for doing this are pretty simplistic and
artificial) but I'd like to get my hands on a *real* example, if
possible.

Grateful for any pointers/suggestions.

cheers,

Rolf Turner

-- 
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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] Converting POSIXct format date to Character format

2021-03-24 Thread Jeff Newmiller
Please don't reply to a thread to start a new question... create a new email to 
avoid linking your question with the one you replied to.

On March 24, 2021 12:11:07 PM PDT, e-mail ma015k3113 via R-help 
 wrote:
>I have a data frame "PLC" which has two variables Year_END_Date   EPS
>
>YEAR_END_Date EPS
>2010-09-10.10
>2009-08-10.20
>
>When I tried to convert Year_END_Date to character format using
>
>select(PLC, format(Year_END_Date,format = "%B %d, %Y"), EPS) I get an
>error
>
>Error: Can't subset columns that don't exist.
>x Column `Year_END_Date` doesn't exist.
>
>I tried using 
>
>PLC_1 <- select(PLC, as.character(YEAR_END_DATE), EPS)
>
>I get the following error
>
>Error: Can't subset columns that don't exist.
>x Columns `2010-09-30`, `2009-09-30`, `2008-09-30`, `2007-09-30`,
>`2006-09-30`, etc. don't exist.
>Run `rlang::last_error()` to see where the error occurred.
>
>Can anyone please guide me what is happening and how can I resolve it?
>
>__
>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.

-- 
Sent from my phone. Please excuse my brevity.

__
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] Calculating column differences

2021-03-24 Thread Jeff Reichman
Bill 

I ended up taking a different approach
miDat <- miDat %>% 
  mutate(new_cases = cases - lag(cases, default = 0))

 - or - 

df <- df %>% 
  mutate(diff = Score - lag(Score, default = 0))

Jeff

-Original Message-
From: William Michels  
Sent: Wednesday, March 24, 2021 1:41 PM
To: r-help@r-project.org
Cc: reichm...@sbcglobal.net; Gerrit Eichner 
Subject: Re: [R] Calculating column differences

More correctly, with an initial "NA" value in the "diff" column:

> df <- data.frame(ID=1:5,Score=4*2:6)
> df1 <- rbind(c(0,0), df)
> cbind(df1, "diff"=c(NA, diff(df1$Score)) )
  ID Score diff
1  0 0   NA
2  1 88
3  2124
4  3164
5  4204
6  5244
>

HTH, Bill.
On Wed, Mar 24, 2021 at 10:59 AM William Michels  wrote:
>
> Dear Jeff,
>
> Rather than diff-ing a linear vector you're trying to diff values from 
> two different rows. Also you indicate that you want to place the 
> diff-ed value in the 'lower' row of a new column. Try this (note 
> insertion of an initial "zero" row):
>
> > df <- data.frame(ID=1:5,Score=4*2:6)
> > df1 <- rbind(c(0,0), df)
> > cbind(df1, "diff"=c(0, diff(df1$Score)) )
>   ID Score diff
> 1  0 00
> 2  1 88
> 3  2124
> 4  3164
> 5  4204
> 6  5244
> >
>
> HTH, Bill.
>
> W. Michels, Ph.D.
>
>
>
> On Wed, Mar 24, 2021 at 9:49 AM Jeff Reichman  wrote:
> >
> > r-help forum
> >
> >
> >
> > I'm trying to calculate the diff between two rows and them mutate 
> > the difference into a new column. I'm using the diff function but 
> > not giving me what I want.
> >
> >
> >
> > df <- data.frame(ID=1:5,Score=4*2:6)
> >
> >
> >
> > What a want  where
> >
> >   ID Score  diff
> >
> > 1  1 8  8
> >
> > 2  212 4
> >
> > 3  316 4
> >
> > 4  420 4
> >
> > 5  524 4
> >
> >
> >
> > What I am getting
> >
> >   ID Score  diff
> >
> > 1  1 8  NA
> >
> > 2  212 4
> >
> > 3  316 4
> >
> > 4  420 4
> >
> > 5  524 4
> >
> >
> >
> > Jeff
> >
> >
> >
> >
> > [[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 for storing value in the matrix

2021-03-24 Thread Ablaye Ngalaba
Hello,
I need help with my R programming code.

I just have a problem storing the matrix calculate Gsigma[m] in sigma.
Seeing what I have coded I find NA value which doesn't generate me errors.


  library(MASS)
# Creation of the linear kernel function
#Function N°1
Kernellin<-function(X,Y){
  return(X%*%t(Y))
}
# Function N°2
SqrtMatrice0<-function(M) {
  # This function allows us to calculate the square root of a matrix
  # using the decomposition M=PDQ where Q is the inverse of P
  # here the negative eigenvalues are replaced by zero
  a=eigen(M,TRUE)
  b=a$values
  b[b<0]=0
  c=a$vectors
  d=diag(sqrt(b))
  b=solve(c)
  a=c%*%d%*%b
  return(a)
}


# declaration of parameters
m1=0.01 # value of alpha (risque de 1%)
m2=0.05 # value of alpha (risque de 5%)
m3=0.1 # value of alpha (risque de 10%)
nbrefoissim=100 # number of times the program runs
p=3 #dimension of the variable X
#q=3 #dimension of the variable Y
#R=c(5,4,3);# Number of partitions of each component of the variable Y
if(length(R) != q) stop("The size of R must be equal to q")
n=25 # Taille echantillon
N=c(25,50,100,200,300,400,500,1000) #different sample sizes
#N=c(25,50) #ifferent sample sizes
pc1=rep(0,100)
K=0
MV=matrix(0,nr=8,nc=4)
dimnames(MV)[[2]]=c("n","r1%","r5%","r10%")


#Start of the programme

for (n in N){


  l1=0 # initialization of the value to calculate the test level at 1%.
  l2=0 # initialization of the value to calculate the test level at 1%. 5%
  l3=0 # initialization of the value to calculate the test level at 1%. 10%

  # Creation of a list nl which contains the sizes of the different groups
  y <- sample(q, 10, TRUE)
  l <- sample(q, 10, TRUE)
  ind <- function(y,l) ifelse(y == l, 1,0)
  for (i in 1:q) {
nl[[i]]<-rep(sum(ind(y,l)),i)
nl[[i]][[i]]=n-((i-1)*nl[[i]][1])
  }
  # Creation of the lists Pl1 and Pl2 which contain the probabilities and
  # the inverses of the empirical probabilities of the different groups
respectively
  pl1<-list()
  pl2<-list()
  for (i in 1:p) {
pl1[[i]]<-nl[[i]]/n
pl2[[i]]<-n/nl[[i]]
  }
  #Creation of a matrix unit
  Tt<-matrix (rep(1, 3*3), 3, 3)
  #Création de matrice
  aa<-c(1,0,1)
  bb<-c(1,1,0)
  TT<-matrix(c(aa,bb),3,3)

  for (i1 in 1:nbrefoissim){
# data generation
X <- mvrnorm(3,rep(0,p),diag(p))

#Sigma calculation

#kernel gram matrix calculation

K1<-TT%*%Kernellin(X,X)%*%t(TT)
k2<-Tt%*%Kernellin(X,X)%*%t(Tt)
k3<-TT%*%Kernellin(X,X)%*%t(Tt)
k4<-Tt%*%Kernellin(X,X)%*%t(TT)
# B calculation
B <- matrix(0, p, p)
for (l in 1:q) {
  B<-B + pl1[[l]][1]*( K1/n^2 - k3/n^2 - k4/n^2 + k2/n^2 )
}
#kernel gram matrix calculation
K5<-t(Tt)%*%Kernellin(X,X)
K6<-Kernellin(X,X)%*%Tt
#V calculation
V <- matrix(0, p, p)
V<-V + (Kernellin(X,X) - K5/n - K6/n - k4/n^2 )/n
#kernel gram matrix calculation
K7<-TT%*%Kernellin(X,X)
K8<-Kernellin(X,X)%*%TT
#W calculation
W<-list()
for (i in 1:p) {
  for (j in 1:p) {
W<-matrix(0, p, p)
Wi<-W + (Kernellin(X,X) - K7/n - K8/n - K1/n^2 )/nl[[i]][1]

Wj<-W + (Kernellin(X,X) - K7/n - K8/n - K1/n^2 )/nl[[j]][3]
  }
}
# T4 calculation
T4<-n*sum(diag(V%*%B))
# GGamma calculation
GGamma<-matrix(0,p*p,p*p)
GGamma<- kronecker(diag(pl2[[i]]), ginv(V))
#GSigma calculation
kron <- function(i, j) ifelse(i==j, 1, 0)

GSigma <- list()
m = 1
for(i in 1:p){

for(j in 1:p){
GSigma[[m]] <- kron(i,j)*pl1[[l]][1]*Wi +pl1[[i]][1]*pl1[[j]][3]*(V
- Wi - Wj )
m <- m+1
  }
}

sigma <- matrix(0, p*p, p*p)
m <- 1
s <- 1
for(i in 1:p){
  r <- i*p
  a <- 1
  for(j in 1:p){
b <- j*p
sigma[s:r, a:b] <-  GSigma[[m]]
m <- m+1
a <- b+1
  }
  s <- r+1
}
# Eigenvalue determinations of sigma epsilon
pa<-SqrtMatrice0(sigma)
mq<- pa %*% GGamma %*% pa
u<-Re(eigen(mq)$values)

# determination of degree of freedom and c-value noted va
dl<-(sum(u)^2)/(sum(u^2))
va<-(sum(u^2))/(sum(u))
pc<-1-pchisq(tr1/va, df= dl)
pc1[i1]<-pc


# Test of the value obtained
if (pc>m1) d1<-0 else d1<-1
if (pc>m2) d2<-0 else d2<-1
if (pc>m3) d3<-0 else d3<-1
l1<-l1+d1
l2<-l2+d2
l3<-l3+d3
  }
  K<-K+1
  MV[K,1]<-n
  MV[K,2]<-l1/nbrefoissim #nbrefoissim=
  MV[K,3]<-l2/nbrefoissim
  MV[K,4]<-l3/nbrefoissim
}
pc


And here is the R code that I used to code mine.


library(MASS)

CentrageV<-function(X,Ms,n){
  # this function centres the data from X
  X1=X*0
  for (i in 1:n){
X1[i,]=X[i,]-Ms
  }
  return(X1)
}


# Fonction N°2
SqrtMatrice0<-function(M) {
  # This function allows us to calculate the square root of a matrix
  # using the decomposition M=PDQ where Q is the inverse of P
  # here the negative eigenvalues are replaced by zero
  a=eigen(M,TRUE)
  b=a$values
  b[b<0]=0
  c=a$vectors
  d=diag(sqrt(b))
  b=solve(c)
  a=c%*%d%*%b
  return(a)
}


# declaration of 

Re: [R] Converting POSIXct format date to Character format

2021-03-24 Thread Rui Barradas

Hello,

R is case sensitive, the column name is YEAR_END_Date, neither of

Year_END_Date
YEAR_END_DATE

matches that name. Try

select(PLC, format(YEAR_END_Date,format = "%B %d, %Y"), EPS)


Hope this helps,

Rui Barradas

Às 19:11 de 24/03/21, e-mail ma015k3113 via R-help escreveu:

I have a data frame "PLC" which has two variables Year_END_Date   EPS

YEAR_END_Date EPS
2010-09-10.10
2009-08-10.20

When I tried to convert Year_END_Date to character format using

select(PLC, format(Year_END_Date,format = "%B %d, %Y"), EPS) I get an error

Error: Can't subset columns that don't exist.
x Column `Year_END_Date` doesn't exist.

I tried using

PLC_1 <- select(PLC, as.character(YEAR_END_DATE), EPS)

I get the following error

Error: Can't subset columns that don't exist.
x Columns `2010-09-30`, `2009-09-30`, `2008-09-30`, `2007-09-30`, `2006-09-30`, 
etc. don't exist.
Run `rlang::last_error()` to see where the error occurred.

Can anyone please guide me what is happening and how can I resolve it?

__
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] Converting POSIXct format date to Character format

2021-03-24 Thread e-mail ma015k3113 via R-help
I have a data frame "PLC" which has two variables Year_END_Date   EPS

YEAR_END_Date EPS
2010-09-10.10
2009-08-10.20

When I tried to convert Year_END_Date to character format using

select(PLC, format(Year_END_Date,format = "%B %d, %Y"), EPS) I get an error

Error: Can't subset columns that don't exist.
x Column `Year_END_Date` doesn't exist.

I tried using 

PLC_1 <- select(PLC, as.character(YEAR_END_DATE), EPS)

I get the following error

Error: Can't subset columns that don't exist.
x Columns `2010-09-30`, `2009-09-30`, `2008-09-30`, `2007-09-30`, `2006-09-30`, 
etc. don't exist.
Run `rlang::last_error()` to see where the error occurred.

Can anyone please guide me what is happening and how can I resolve it?

__
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] Calculating column differences

2021-03-24 Thread William Michels via R-help
More correctly, with an initial "NA" value in the "diff" column:

> df <- data.frame(ID=1:5,Score=4*2:6)
> df1 <- rbind(c(0,0), df)
> cbind(df1, "diff"=c(NA, diff(df1$Score)) )
  ID Score diff
1  0 0   NA
2  1 88
3  2124
4  3164
5  4204
6  5244
>

HTH, Bill.
On Wed, Mar 24, 2021 at 10:59 AM William Michels  wrote:
>
> Dear Jeff,
>
> Rather than diff-ing a linear vector you're trying to diff values from
> two different rows. Also you indicate that you want to place the
> diff-ed value in the 'lower' row of a new column. Try this (note
> insertion of an initial "zero" row):
>
> > df <- data.frame(ID=1:5,Score=4*2:6)
> > df1 <- rbind(c(0,0), df)
> > cbind(df1, "diff"=c(0, diff(df1$Score)) )
>   ID Score diff
> 1  0 00
> 2  1 88
> 3  2124
> 4  3164
> 5  4204
> 6  5244
> >
>
> HTH, Bill.
>
> W. Michels, Ph.D.
>
>
>
> On Wed, Mar 24, 2021 at 9:49 AM Jeff Reichman  wrote:
> >
> > r-help forum
> >
> >
> >
> > I'm trying to calculate the diff between two rows and them mutate the
> > difference into a new column. I'm using the diff function but not giving me
> > what I want.
> >
> >
> >
> > df <- data.frame(ID=1:5,Score=4*2:6)
> >
> >
> >
> > What a want  where
> >
> >   ID Score  diff
> >
> > 1  1 8  8
> >
> > 2  212 4
> >
> > 3  316 4
> >
> > 4  420 4
> >
> > 5  524 4
> >
> >
> >
> > What I am getting
> >
> >   ID Score  diff
> >
> > 1  1 8  NA
> >
> > 2  212 4
> >
> > 3  316 4
> >
> > 4  420 4
> >
> > 5  524 4
> >
> >
> >
> > Jeff
> >
> >
> >
> >
> > [[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] Calculating column differences

2021-03-24 Thread Jeff Reichman
Gerrit

 

Changed my approach 

 

df <- data.frame(ID=1:5,Score=4*2:6)

 

df %>% 

  mutate(score_diff = Score - lag(Score, default = 0))

 

Jeff

 

-Original Message-
From: R-help  On Behalf Of Gerrit Eichner
Sent: Wednesday, March 24, 2021 11:53 AM
To: r-help@r-project.org
Subject: Re: [R] Calculating column differences

 

Dear Jeff,

 

read diff's help page, and you'll find out what is wrong with your expectation.

 

What do think diff(df$Score) should give for the first element in df$Score??

 

  Hth  --  Gerrit

 

-

Dr. Gerrit Eichner   Mathematical Institute, Room 212

  gerrit.eich...@math.uni-giessen.de 
  Justus-Liebig-University Giessen

Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany

  http://www.uni-giessen.de/eichner

-



Am 24.03.2021 um 17:48 schrieb Jeff Reichman:

> r-help forum

> 

>   

> 

> I'm trying to calculate the diff between two rows and them mutate the 

> difference into a new column. I'm using the diff function but not 

> giving me what I want.

> 

>   

> 

> df <- data.frame(ID=1:5,Score=4*2:6)

> 

>   

> 

> What a want  where

> 

>ID Score  diff

> 

> 1  1 8  8

> 

> 2  212 4

> 

> 3  316 4

> 

> 4  420 4

> 

> 5  524 4

> 

>   

> 

> What I am getting

> 

>ID Score  diff

> 

> 1  1 8  NA

> 

> 2  212 4

> 

> 3  316 4

> 

> 4  420 4

> 

> 5  524 4

> 

>   

> 

> Jeff

> 

>   

> 

> 

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


[[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] converting image formats

2021-03-24 Thread Vivek Sutradhara
Hi,
I have made a few corrections to my previous message in the naming of my
objects.

I would like to have help in converting from one image format to another
(between the packages EBImage, magick and imager). The magick package has
functions for this. But the EBImage and imager packages do not have
in-built functions for the conversion. It is, of course, possible to save
the images and then open with the other packages. But I am looking for more
direct options. I do not know how to assign data to the "slots" in the
functions.
### convert image formats
library(magick)
nuc_MAG_o <- image_read(system.file("images", "nuclei.tif",
package="EBImage"))
nuc_MAG_to_EB <- as_EBImage(nuc_MAG_o)
nuc_MAG_to_IMG <- magick2cimg(nuc_MAG_o,alpha="flatten")

# convert from EBImage
library(EBImage)
nuc_EB_o <-  readImage(system.file("images", "nuclei.tif",
package="EBImage"))
writeImage(nucEBo, "C:/Rfiles/nuclei-3.jpg")
# to convert nuc_EB_o
nucEB_to_IMG <-
nucEB_to_MAG <-

#convert from imager
library(imager)
nuc_IMG_o <- load.image("C:/Rfiles/nuclei-3.jpg")
# to convert nuc_IMG_o
nuc_IMG_to_EB <-
nuc_IMG_to_MAG <-
Thanks,
Vivek

Den ons 24 mars 2021 kl 18:54 skrev Vivek Sutradhara :

> Hi,
> I would like to have help in converting from one image format to another
> (between the packages EBImage, magick and imager). The magick package has
> functions for this. But the EBImage and imager packages do not have
> in-built functions for the conversion. It is, of course, possible to save
> the images and then open with the other packages. But I am looking for more
> direct options. I do not know how to assign data to the "slots" in the
> functions.
>
> ### convert image formats
> library(magick)
> nuc_MAG_o <- image_read(system.file("images", "nuclei.tif",
> package="EBImage"))
> nuc_MAG_to_EB <- as_EBImage(manMAG)
> nuc_MAG_to_IMG <- magick2cimg(manMAG,alpha="flatten")
>
> # convert from EBImage
> library(EBImage)
> nucEBo <-  readImage(system.file("images", "nuclei.tif",
> package="EBImage"))
> writeImage(nucEBo, "C:/Rfiles/nuclei-3.jpg")
> nucEB_to_IMG <-
> nucEB_to_MAG <-
>
> #convert from imager
> library(imager)
> nuc_IMG_o <- load.image("C:/Rfiles/nuclei-3.jpg")
> nuc_IMG_to_EB <-
> nuc_IMG_to_MAG <-
>
> All help is appreciated.
> Thanks,
> Vivek
>

[[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] Calculating column differences

2021-03-24 Thread William Michels via R-help
Dear Jeff,

Rather than diff-ing a linear vector you're trying to diff values from
two different rows. Also you indicate that you want to place the
diff-ed value in the 'lower' row of a new column. Try this (note
insertion of an initial "zero" row):

> df <- data.frame(ID=1:5,Score=4*2:6)
> df1 <- rbind(c(0,0), df)
> cbind(df1, "diff"=c(0, diff(df1$Score)) )
  ID Score diff
1  0 00
2  1 88
3  2124
4  3164
5  4204
6  5244
>

HTH, Bill.

W. Michels, Ph.D.



On Wed, Mar 24, 2021 at 9:49 AM Jeff Reichman  wrote:
>
> r-help forum
>
>
>
> I'm trying to calculate the diff between two rows and them mutate the
> difference into a new column. I'm using the diff function but not giving me
> what I want.
>
>
>
> df <- data.frame(ID=1:5,Score=4*2:6)
>
>
>
> What a want  where
>
>   ID Score  diff
>
> 1  1 8  8
>
> 2  212 4
>
> 3  316 4
>
> 4  420 4
>
> 5  524 4
>
>
>
> What I am getting
>
>   ID Score  diff
>
> 1  1 8  NA
>
> 2  212 4
>
> 3  316 4
>
> 4  420 4
>
> 5  524 4
>
>
>
> Jeff
>
>
>
>
> [[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] converting image formats

2021-03-24 Thread Vivek Sutradhara
Hi,
I would like to have help in converting from one image format to another
(between the packages EBImage, magick and imager). The magick package has
functions for this. But the EBImage and imager packages do not have
in-built functions for the conversion. It is, of course, possible to save
the images and then open with the other packages. But I am looking for more
direct options. I do not know how to assign data to the "slots" in the
functions.

### convert image formats
library(magick)
nuc_MAG_o <- image_read(system.file("images", "nuclei.tif",
package="EBImage"))
nuc_MAG_to_EB <- as_EBImage(manMAG)
nuc_MAG_to_IMG <- magick2cimg(manMAG,alpha="flatten")

# convert from EBImage
library(EBImage)
nucEBo <-  readImage(system.file("images", "nuclei.tif", package="EBImage"))
writeImage(nucEBo, "C:/Rfiles/nuclei-3.jpg")
nucEB_to_IMG <-
nucEB_to_MAG <-

#convert from imager
library(imager)
nuc_IMG_o <- load.image("C:/Rfiles/nuclei-3.jpg")
nuc_IMG_to_EB <-
nuc_IMG_to_MAG <-

All help is appreciated.
Thanks,
Vivek

[[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] setRefClass in package

2021-03-24 Thread Jeremie Juste
Hello,


Many thanks for the reply.
Indeed there was no scoping issue here. I was sloppy.

Best regards,
Jeremie


On Wednesday, 24 Mar 2021 at 11:34, Duncan Murdoch wrote:
> On 24/03/2021 9:06 a.m., Jeremie Juste wrote:
>> Hello,
>> I was wondering how to call a function outside a setRefClass but
>> inside
>> the package without export it. Let me explain by means of an example.
>
> There are no scoping issues here:  Your initialize method can see all
> local functions in the package, including remove_if_all_NA.  But
> you've got a typo:  you called remove_if_all_na instead.  NA is not
> the same as na!
>
> Duncan Murdoch
>
>> - in the file test-package/R/test.R
>> ##' some description
>> ##'
>> ##' some details
>> ##' @title test
>> ##' @return sideeffect
>> ##' @author Jeremie Juste
>> ##' @export test
>> ##' @import data.table
>> test <- setRefClass("test",
>>  list(dt="data.table"))
>> test$methods(
>>   initialize = function(x){
>>  dt <<- remove_if_all_na(x[,abc:=1])
>>  }
>> )
>> ##' remove rows for which all values are NA
>> ##'
>> ##' @title remove_if_all_NA
>> ##' @param dt
>> ##' @return dt
>> ##' @author Jeremie Juste
>> remove_if_all_NA <- function(dt) {
>>cn <- colnames(dt)
>>dt[!dt[NA],on=cn]
>> }
>> Here when I build and install the package test-package, if I don't
>> export
>> remove_if_all_NA
>> ##' remove rows for which all values are NA
>> ##'
>> ##' @title remove_if_all_NA
>> ##' @param dt
>> ##' @return dt
>> ##' @author Jeremie Juste
>> ##' @export
>> remove_if_all_NA <- function(dt) {
>>cn <- colnames(dt)
>>dt[!dt[NA],on=cn]
>> }
>> The package cannot use it.
>> library(test-package)
>> library(data.table)
>> 
>>> aa <- data.table(a=1:10,b=letters[1:10])
>>> b <- test(aa)
>> Error in remove_if_all_na(x[, `:=`(abc, 1)]) :
>>could not find function "remove_if_all_na"
>> Do you have any recommendations? The official documentation for
>> setRefClass is a bit thin for me but I wanted to use a tools that is going 
>> to stay. Any tip is
>> welcome.
>> Best regards,
>> Jeremie
>> __
>> 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.
>> 
>

-- 
Jeremie Juste

__
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] Calculating column differences

2021-03-24 Thread Gerrit Eichner

Dear Jeff,

read diff's help page, and you'll find out
what is wrong with your expectation.

What do think diff(df$Score) should give for
the first element in df$Score??

 Hth  --  Gerrit

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
http://www.uni-giessen.de/eichner
-

Am 24.03.2021 um 17:48 schrieb Jeff Reichman:

r-help forum

  


I'm trying to calculate the diff between two rows and them mutate the
difference into a new column. I'm using the diff function but not giving me
what I want.

  


df <- data.frame(ID=1:5,Score=4*2:6)

  


What a want  where

   ID Score  diff

1  1 8  8

2  212 4

3  316 4

4  420 4

5  524 4

  


What I am getting

   ID Score  diff

1  1 8  NA

2  212 4

3  316 4

4  420 4

5  524 4

  


Jeff

  



[[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] Calculating column differences

2021-03-24 Thread Jeff Reichman
r-help forum

 

I'm trying to calculate the diff between two rows and them mutate the
difference into a new column. I'm using the diff function but not giving me
what I want. 

 

df <- data.frame(ID=1:5,Score=4*2:6)

 

What a want  where 

  ID Score  diff

1  1 8  8

2  212 4

3  316 4

4  420 4

5  524 4

 

What I am getting

  ID Score  diff

1  1 8  NA

2  212 4

3  316 4

4  420 4

5  524 4

 

Jeff

 


[[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] setRefClass in package

2021-03-24 Thread Duncan Murdoch

On 24/03/2021 9:06 a.m., Jeremie Juste wrote:

Hello,

I was wondering how to call a function outside a setRefClass but inside
the package without export it. Let me explain by means of an example.


There are no scoping issues here:  Your initialize method can see all 
local functions in the package, including remove_if_all_NA.  But you've 
got a typo:  you called remove_if_all_na instead.  NA is not the same as na!


Duncan Murdoch



- in the file test-package/R/test.R

##' some description
##'
##' some details
##' @title test
##' @return sideeffect
##' @author Jeremie Juste
##' @export test
##' @import data.table
test <- setRefClass("test",
 list(dt="data.table"))


test$methods(
   
   initialize = function(x){

 dt <<- remove_if_all_na(x[,abc:=1])
 }
)


##' remove rows for which all values are NA
##'
##' @title remove_if_all_NA
##' @param dt
##' @return dt
##' @author Jeremie Juste
remove_if_all_NA <- function(dt) {
   cn <- colnames(dt)
   dt[!dt[NA],on=cn]
}


Here when I build and install the package test-package, if I don't export
remove_if_all_NA

##' remove rows for which all values are NA
##'
##' @title remove_if_all_NA
##' @param dt
##' @return dt
##' @author Jeremie Juste
##' @export
remove_if_all_NA <- function(dt) {
   cn <- colnames(dt)
   dt[!dt[NA],on=cn]
}

The package cannot use it.

library(test-package)
library(data.table)


aa <- data.table(a=1:10,b=letters[1:10])
b <- test(aa)

Error in remove_if_all_na(x[, `:=`(abc, 1)]) :
   could not find function "remove_if_all_na"

Do you have any recommendations? The official documentation for
setRefClass is a bit thin for me but I wanted to use a tools that is going to 
stay. Any tip is
welcome.

Best regards,
Jeremie

__
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] setRefClass in package

2021-03-24 Thread Bert Gunter
I think this query fits better on r-package-devel rather than here.

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 Wed, Mar 24, 2021 at 6:07 AM Jeremie Juste 
wrote:

> Hello,
>
> I was wondering how to call a function outside a setRefClass but inside
> the package without export it. Let me explain by means of an example.
>
> - in the file test-package/R/test.R
>
> ##' some description
> ##'
> ##' some details
> ##' @title test
> ##' @return sideeffect
> ##' @author Jeremie Juste
> ##' @export test
> ##' @import data.table
> test <- setRefClass("test",
> list(dt="data.table"))
>
>
> test$methods(
>
>   initialize = function(x){
> dt <<- remove_if_all_na(x[,abc:=1])
> }
> )
>
>
> ##' remove rows for which all values are NA
> ##'
> ##' @title remove_if_all_NA
> ##' @param dt
> ##' @return dt
> ##' @author Jeremie Juste
> remove_if_all_NA <- function(dt) {
>   cn <- colnames(dt)
>   dt[!dt[NA],on=cn]
> }
>
>
> Here when I build and install the package test-package, if I don't export
> remove_if_all_NA
>
> ##' remove rows for which all values are NA
> ##'
> ##' @title remove_if_all_NA
> ##' @param dt
> ##' @return dt
> ##' @author Jeremie Juste
> ##' @export
> remove_if_all_NA <- function(dt) {
>   cn <- colnames(dt)
>   dt[!dt[NA],on=cn]
> }
>
> The package cannot use it.
>
> library(test-package)
> library(data.table)
>
> > aa <- data.table(a=1:10,b=letters[1:10])
> > b <- test(aa)
> Error in remove_if_all_na(x[, `:=`(abc, 1)]) :
>   could not find function "remove_if_all_na"
>
> Do you have any recommendations? The official documentation for
> setRefClass is a bit thin for me but I wanted to use a tools that is going
> to stay. Any tip is
> welcome.
>
> Best regards,
> Jeremie
>
> __
> 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] setRefClass in package

2021-03-24 Thread Jeremie Juste
Hello,

I was wondering how to call a function outside a setRefClass but inside
the package without export it. Let me explain by means of an example.

- in the file test-package/R/test.R

##' some description
##'
##' some details
##' @title test
##' @return sideeffect
##' @author Jeremie Juste
##' @export test
##' @import data.table
test <- setRefClass("test",
list(dt="data.table"))


test$methods(
  
  initialize = function(x){
dt <<- remove_if_all_na(x[,abc:=1])
}
)


##' remove rows for which all values are NA
##'
##' @title remove_if_all_NA
##' @param dt 
##' @return dt
##' @author Jeremie Juste
remove_if_all_NA <- function(dt) {
  cn <- colnames(dt)
  dt[!dt[NA],on=cn]  
}


Here when I build and install the package test-package, if I don't export
remove_if_all_NA 

##' remove rows for which all values are NA
##'
##' @title remove_if_all_NA
##' @param dt 
##' @return dt
##' @author Jeremie Juste
##' @export
remove_if_all_NA <- function(dt) {
  cn <- colnames(dt)
  dt[!dt[NA],on=cn]  
}

The package cannot use it.

library(test-package)
library(data.table)

> aa <- data.table(a=1:10,b=letters[1:10])
> b <- test(aa)
Error in remove_if_all_na(x[, `:=`(abc, 1)]) : 
  could not find function "remove_if_all_na"

Do you have any recommendations? The official documentation for
setRefClass is a bit thin for me but I wanted to use a tools that is going to 
stay. Any tip is
welcome.

Best regards,
Jeremie

__
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] Probit model- endogeneity issue

2021-03-24 Thread hannelore nelissen
Dear all,
I am having some issues with using the IV strategy for an endogeneity problem 
in terms of a probit model.  In particular, I want to follow a two-stage 
procedure where I estimate a probit on the decision to peg the exchange rate, 
and then use the predicted values in the second stage regression. So, I need to 
get a probability that the country has a peg (estimated based on the Z 
variables). So, in the second stage, I have to include this estimated 
probability of the first stage (and exclude the Z variables that showed a 
significant effect). However, I do not know how to get this estimated 
probability of the first stage which I can then include in my second stage?
Can somebody help me with the command I should use?


I would really appreciate it, thanks Dear all,




Verzonden vanuit Mail voor 
Windows 10


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