Re: [R] (no subject)

2024-09-16 Thread CALUM POLWART
Rui's solution is good.

Bert's suggestion is also good!

For Berts suggestion you'd make the list bit

list(mean = mean_narm)

But prior to that define a function:

mean_narm<- function(x) {

m <- mean(x, na.rm = T)

if (!is.Nan (m)) {
m <- NA
}

return (m)
}

Would do what you suggested in your reply to Bert.

On Mon, 16 Sep 2024, 19:48 Rui Barradas,  wrote:

> Às 15:23 de 16/09/2024, Francesca escreveu:
> > Sorry for posting a non understandable code. In my screen the dataset
> > looked correctly.
> >
> >
> > I recreated my dataset, folllowing your example:
> >
> > test<-data.frame(matrix(c( 8,  8,  5 , 5 ,NA ,NA , 1, 15, 20,  5, NA, 17,
> >   2 , 5 , 5,  2 , 5 ,NA,  5 ,10, 10,  5 ,12, NA),
> >  c( 18,  5,  5,  5, NA,  9,  2,  2, 10,  7 , 5,
> 19,
> > NA, 10, NA, 4, NA,  8, NA,  5, 10,  3, 17, NA),
> >  c( 4, 3, 3, 2, 2, 4, 3, 3, 2, 4, 4 ,3, 4, 4, 4,
> 2,
> > 2, 3, 2, 3, 3, 2, 2 ,4),
> >  c(3, 8, 1, 2, 4, 2, 7, 6, 3, 5, 1, 3, 8, 4, 7,
> 5,
> > 8, 5, 1, 2, 4, 7, 6, 6)))
> > colnames(test)<-c("cp1","cp2","role","groupid")
> >
> > What I have done so far is the following, that works:
> >   test %>%
> >group_by(groupid) %>%
> >mutate(across(starts_with("cp"), list(mean = mean)))
> >
> > But the problem is with NA: everytime the mean encounters a NA, it
> creates
> > NA for all group members.
> > I need the software to calculate the mean ignoring NA. So when the group
> is
> > made of three people, mean of the three.
> > If the group is two values and an NA, calculate the mean of two.
> >
> > My code works , creates a mean at each position for three subjects,
> > replacing instead of the value of the single, the group mean.
> > But when NA appears, all the group gets NA.
> >
> > Perhaps there is a different way to obtain the same result.
> >
> >
> >
> > On Mon, 16 Sept 2024 at 11:35, Rui Barradas 
> wrote:
> >
> >> Às 08:28 de 16/09/2024, Francesca escreveu:
> >>> Dear Contributors,
> >>> I hope someone has found a similar issue.
> >>>
> >>> I have this data set,
> >>>
> >>>
> >>>
> >>> cp1
> >>> cp2
> >>> role
> >>> groupid
> >>> 1
> >>> 10
> >>> 13
> >>> 4
> >>> 5
> >>> 2
> >>> 5
> >>> 10
> >>> 3
> >>> 1
> >>> 3
> >>> 7
> >>> 7
> >>> 4
> >>> 6
> >>> 4
> >>> 10
> >>> 4
> >>> 2
> >>> 7
> >>> 5
> >>> 5
> >>> 8
> >>> 3
> >>> 2
> >>> 6
> >>> 8
> >>> 7
> >>> 4
> >>> 4
> >>> 7
> >>> 8
> >>> 8
> >>> 4
> >>> 7
> >>> 8
> >>> 10
> >>> 15
> >>> 3
> >>> 3
> >>> 9
> >>> 15
> >>> 10
> >>> 2
> >>> 2
> >>> 10
> >>> 5
> >>> 5
> >>> 2
> >>> 4
> >>> 11
> >>> 20
> >>> 20
> >>> 2
> >>> 5
> >>> 12
> >>> 9
> >>> 11
> >>> 3
> >>> 6
> >>> 13
> >>> 10
> >>> 13
> >>> 4
> >>> 3
> >>> 14
> >>> 12
> >>> 6
> >>> 4
> >>> 2
> >>> 15
> >>> 7
> >>> 4
> >>> 4
> >>> 1
> >>> 16
> >>> 10
> >>> 0
> >>> 3
> >>> 7
> >>> 17
> >>> 20
> >>> 15
> >>> 3
> >>> 8
> >>> 18
> >>> 10
> >>> 7
> >>> 3
> >>> 4
> >>> 19
> >>> 8
> >>> 13
> >>> 3
> >>> 5
> >>> 20
> >>> 10
> >>> 9
> >>> 2
> >>> 6
> >>>
> >>>
> >>>
> >>> I need to to average of groups, using the values of column groupid, and
> >>> create a twin dataset in which the mean of the group is replaced
> instead
> >> of
> >>> individual values.
> >>> So for example, groupid 3, I calculate the mean (12+18)/2 and then I
> >>> replace in the new dataframe, but in the same positions, instead of 12
> >> and
> >>> 18, the values of the corresponding mean.
> >>> I found this solution, where db10_means is the output dataset, db10 is
> my
> >>> initial data.
> >>>
> >>> db10_means<-db10 %>%
> >>> group_by(groupid) %>%
> >>> mutate(across(starts_with("cp"), list(mean = mean)))
> >>>
> >>> It works perfectly, except that for NA values, where it replaces to all
> >>> group members the NA, while in some cases, the group is made of some NA
> >> and
> >>> some values.
> >>> So, when I have a group of two values and one NA, I would like that for
> >>> those with a value, the mean is replaced, for those with NA, the NA is
> >>> replaced.
> >>> Here the mean function has not the na.rm=T option associated, but it
> >>> appears that this solution cannot be implemented in this case. I am not
> >>> even sure that this would be enough to solve my problem.
> >>> Thanks for any help provided.
> >>>
> >> Hello,
> >>
> >> Your data is a mess, please don't post html, this is plain text only
> >> list. Anyway, I managed to create a data frame by copying the data to a
> >> file named "rhelp.txt" and then running
> >>
> >>
> >>
> >> db10 <- scan(file = "rhelp.txt", what = character())
> >> header <- db10[1:4]
> >> db10 <- db10[-(1:4)] |> as.numeric()
> >> db10 <- matrix(db10, ncol = 4L, byrow = TRUE) |>
> >> as.data.frame() |>
> >> setNames(header)
> >>
> >> str(db10)
> >> #> 'data.frame':25 obs. of  4 variables:
> >> #>  $ cp1: num  1 5 3 7 10 5 2 4 8 10 ...
> >> #>  $ cp2: num  10 2 1 4 4 5 6 4 4 15 ...
> >> #>  $ role   : num  13 5 3 6 2 8 8 7 7 3 ...
> >> #>  $ groupid: num  4 10 7 4 7 3 7 8 8 3 ...
> >>
> >>
> >> And here 

Re: [R] how to specify point symbols in the key on a lattice dotplot

2024-09-13 Thread CALUM POLWART
Add:

key = list(points=16:17)

Into the dotplot section possibly without the autokey

On Fri, 13 Sep 2024, 08:19 Christopher W. Ryan, 
wrote:

> I am making a dotplot with lattice, as follows:
>
> dd %>% dotplot( segment ~ transit_time, groups = impact,  data = .,
>as.table = TRUE,
> pch = 16:17,
> cex = 1.8,
> scales = list(cex = 1.4),
>auto.key = TRUE)
>
> impact is a factor with two levels.
>
> They key shows 2 open circles, one of each color of my two
> plotting symbols, one for each group. I would like the
> symbols in the key to match the plotting characters in the graph: 16
> (filled circle) for one group and 17 (filled triangle) for the second
> group.  How would I do that? I have not had any success with supplying
> arguments to auto.key, simpleKey, or key. Guess I'm not understanding
> the syntax.
>
> Thanks.
>
> --Chris Ryan
>
> --
> Agency Statistical Consulting, LLC
> Helping those in public service get the most from their data.
> www.agencystatistical.com
>
> Public GnuPG email encryption key at
> https://keys.openpgp.org
> 9E53101D261BEC070CFF1A0DC8BC50E715A672A0
>
> __
> 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
> https://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 https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fill NA values in columns with values of another column

2024-08-27 Thread CALUM POLWART
Bert

I thought she meant she wanted to replace the NAs with the 6. But I could
be wrong.

It looks like the data is combined from cbind.

I'm going to give tidyverse examples because it's (/s) *"always"* (/s)
easier.

require(tidyverse)
# impute the missing NAs
myData <- cbind(VB1d[,1],s1id[,1])

myData |> said[
  filter(!is.na(1)) |>  #uses col1 would be better to use a name
  unique() -> referenceData

myData |>
  select(2) |> #better to name
  left_join(referenceData) -> cleanData

You will notice I've used column numbers. I suspect cbind will name the
columns oddly. And I'm typing this on my phone so it's untested.

If you wanted counts

myData |>
  filter (!is.na(1)) |>
  group_by(2) |>
  summarise (n())

I won't answer the c(5,5) that Bert mentions because that's an extra
question of what you do next with the data to know how best to present it.

On Wed, 28 Aug 2024, 00:06 Bert Gunter,  wrote:

> Sorry, not clear to me.
>
> For group 8 in your example, do you want extract the values in column
> 1 that are not NA, i.e. one value, 6; or do you want to extract the
> number of values -- that is, the count --  that are not NA, i.e. 1?
>
> ... and for group 5, would it be c(9,9) for the values; or 2 for the count?
>
> Or something else entirely if I have completely misunderstood.
>
> Either of the above are easy and quick to do. You can also just remove
>  the NA's via a version of ?na.omit if that's what you want.
>
> Of course, feel free to ignore this and wait for a more helpful
> response from someone who understands your query better than I.
>
> Cheers,
> Bert
>
> On Tue, Aug 27, 2024 at 3:45 PM Francesca PANCOTTO via R-help
>  wrote:
> >
> > Dear Contributors,
> > I have a problem with a database composed of many individuals for many
> > periods, for which I need to perform a manipulation of data as follows.
> > Here I report the procedure I need to do for the first 32 observations of
> > the first period.
> >
> >
> > cbind(VB1d[,1],s1id[,1])
> >   [,1] [,2]
> >  [1,]68
> >  [2,]95
> >  [3,]   NA1
> >  [4,]56
> >  [5,]   NA7
> >  [6,]   NA2
> >  [7,]44
> >  [8,]27
> >  [9,]27
> > [10,]   NA3
> > [11,]   NA2
> > [12,]   NA4
> > [13,]56
> > [14,]95
> > [15,]   NA5
> > [16,]   NA6
> > [17,]   103
> > [18,]72
> > [19,]21
> > [20,]   NA7
> > [21,]72
> > [22,]   NA8
> > [23,]   NA4
> > [24,]   NA5
> > [25,]   NA6
> > [26,]21
> > [27,]44
> > [28,]68
> > [29,]   103
> > [30,]   NA3
> > [31,]   NA8
> > [32,]   NA1
> >
> >
> > In column s1id, I have numbers from 1 to 8, which are the id of 8 groups
> ,
> > randomly mixed in the larger group of 32.
> > For each group, I want the value that is reported for only to group
> > members, to all the four group members.
> >
> > For example, value 8 in first row , second column, is group 8. The value
> > for group 8 of the variable VB1d is 6. At row 28, again for s1id equal to
> > 8, I have 6.
> > But in row 22, the value 8 of the second variable, reports a value NA.
> > in each group is the same, only two values have the correct number, the
> > other two are NA.
> > I need that each group, identified by the values of the variable S1id,
> > correctly report the number of variable VB1d that is present for just two
> > group members.
> >
> > I hope my explanation is acceptable.
> > The task appears complex to me right now, especially because I will need
> to
> > multiply this procedure for x12x14 similar databases.
> >
> > Anyone has ever encountered a similar problem?
> > Thanks in advance for any help provided.
> >
> > --
> >
> > Francesca Pancotto
> >
> > Associate Professor Political Economy
> >
> > University of Modena, Largo Santa Eufemia, 19, Modena
> >
> > Office Phone: +39 0522 523264
> >
> > Web: *https://sites.google.com/view/francescapancotto/home
> > *
> >
> >  --
> >
> > [[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
> https://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
> https://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
PLEAS

Re: [R] Terminating a cmd windows from R

2024-08-17 Thread CALUM POLWART
cmd
taskkill /PID 1234

Will kill process 1234 if you know it id

So shell.exec can likely do this for you

On Sat, 17 Aug 2024, 12:31 Duncan Murdoch,  wrote:

> On 2024-08-17 6:21 a.m., SIMON Nicolas via R-help wrote:
> > I would like to stop a dos shell windows following the cmd (execute)
> command. Is there a way to do that from R?
>
> I think you need to give more detail on what you are trying to do.  In
> Windows, "cmd" is supposed to open a shell window.   Could you show us
> an example of what you are doing?
>
> Duncan Murdoch
>
> __
> 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
> https://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 https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] boxplot notch

2024-08-16 Thread CALUM POLWART
Unless I'm missing the point, you are sending the summary data MS1s to the
plot.  Is that not a VERY unusual way to do it. Let box plot do the
summary? Otherwise what do you want the notches to show?

On Fri, 16 Aug 2024, 17:21 Chris Evans via R-help, 
wrote:

> That's not really a reprex Sibylle.  I did try to use it to see if I
> could work out what you were trying to do and help but there is so much
> in there that I suspect is distraction from the notch issue and its
> error message.
>
> Please can you give us something stripped of all unecessary things and
> tell us what you want?
>
> Something like data that we can read as a tribble() or from a dput() of
> your data and then only the packages you actually need for the plot (I
> think tidyverse alone might do) and then a ggplot() call stripped right
> down to what you need and a clear explanation of what you are trying to
> do in the geom_boxplot() call and how it uses the summarised data tibble.
>
> It may even be that if you do that, you will find what's causing the
> problem!  (I speak from bitter experience!!)
>
> Very best (all),
>
> Chris
>
> On 16/08/2024 17:51, SIBYLLE STÖCKLI via R-help wrote:
> > Farm_ID   JahrBio QI_A
> > 1 20151   9.5
> > 2 20181   15.7
> > 3 20201   21.5
> > 1 20151   50.5
> > 2 20181   12.9
> > 3 20201   11.2
> > 1 20151   30.6
> > 2 20181   28.7
> > 3 20201   29.8
> > 1 20151   30.1
> > 2 20181   NA
> > 3 20201   16.9
> > 1 20150   6.5
> > 2 20180   7.9
> > 3 20200   10.2
> > 1 20150   11.2
> > 2 20180   18.5
> > 3 20200   29.5
> > 1 20150   25.1
> > 2 20180   16.1
> > 3 20200   15.9
> > 1 20150   10.1
> > 2 20180   8.4
> > 3 20200   3.5
> > 1 20150   NA
> > 2 20180   NA
> > 3 20200   3.5
> >
> >
> > Code
> > setwd("C:/Users/Sibylle Stöckli/Desktop/")
> > #.libPaths()
> > getwd()
> >
> > #libraries laden
> > library("ggplot2")
> > library("gridExtra")
> > library(scales)
> > library(nlme)
> > library(arm)
> > library(blmeco)
> > library(stats)
> > library(dplyr)
> > library(ggpubr)
> > library(patchwork)
> > library(plotrix)
> > library(tidyverse)
> > library(dplyr)
> >
> > #read data
> > MS = read.delim("Test1.txt", na.strings="NA")
> > names(MS)
> >
> > MS$Jahr<-as.numeric(MS$Jahr)
> > MS$Bio<-as.factor(MS$Bio)
> > str(MS)
> >
> > # boxplot BFF QI
> >
> > MS1<- MS %>% filter(QI_A!="NA") %>% droplevels()
> > MS1$Jahr<-as.factor(MS1$Jahr)
> >
> > MS1s <- MS1 %>%
> >group_by(MS1$Jahr, MS1$Bio) %>%
> >summarise(
> >  y0 = quantile(QI_A, 0.05),
> >  y25 = quantile(QI_A, 0.25),
> >  y50 = mean(QI_A),
> >  y75 = quantile(QI_A, 0.75),
> >  y100 = quantile(QI_A, 0.95))
> >
> > MS1s
> > colnames(MS1s)[1]<-"Jahr"
> > colnames(MS1s)[2]<-"Bio"
> > MS1s
> >
> > p1<-ggplot(MS1s, aes(Jahr,  fill = as.factor(Bio))) +
> >geom_boxplot(
> >  aes(ymin = y0, lower = y25, middle = y50, upper = y75, ymax = y100),
> >  stat = "identity", notch=TRUE
> >) +
> >theme(panel.background = element_blank())+
> >theme(axis.line = element_line(colour = "black"))+
> >theme(axis.text=element_text(size=18))+
> >theme(axis.title=element_text(size=20))+
> >ylab("Anteil BFF an LN [%]") +xlab("Jahr")+
> >scale_color_manual(values=c("red","darkgreen"), labels=c("ÖLN",
> "BIO"))+
> >scale_fill_manual(values=c("red","darkgreen"), labels= c("ÖLN",
> "BIO"))+
> >theme(legend.title = element_blank())+
> >theme(legend.text=element_text(size=20))
> > p1<-p1 + expand_limits(y=c(0, 80))
> > p1
> --
> Chris Evans (he/him)
> Visiting Professor, UDLA, Quito, Ecuador & Honorary Professor,
> University of Roehampton, London, UK.
> Work web site: https://www.psyctc.org/psyctc/
> CORE site: http://www.coresystemtrust.org.uk/
> Personal site: https://www.psyctc.org/pelerinage2016/
> Emeetings (Thursdays):
> https://www.psyctc.org/psyctc/booking-meetings-with-me/
> (Beware: French time, generally an hour ahead of UK)
> 
> [[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
> https://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 https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] If loop

2024-08-09 Thread CALUM POLWART
Oh I thought that was just my experience of it !! So didn't want to slate
it too much!!

Yes, I nearly said "without making it an object of objects". I guess it
depends what they want to do with those objects in the end.

Usually if I want a function to manipulate two things I create two
functions.

On Fri, 9 Aug 2024, 11:21 Bert Gunter,  wrote:

> "Or use <<- assignment I think.  (I usually return, but return can only
> return one object and I think you want two or more"
>
> You can return any number of objects by putting them in a list and
> returning the list.
> Use of "<<-" is rarely a good idea in R.
>
> -- Bert
>
> On Fri, Aug 9, 2024 at 1:53 AM CALUM POLWART  wrote:
> >
> > OK. The fact it's in a function is making things clearer.
> >
> > Are you trying to update the values of an object from within the
> function,
> > and have them available outside the function. I don't speak functional
> > programming articulately enough but basically
> >
> > v <- 1
> >
> > funA <- function() {
> > v <- v+1
> > }
> >
> > funA()
> > cat (v)
> >
> > # 1
> >
> > You either return the v from the function so
> >
> > funB <- function() {
> > v <- v+1
> > return (v)
> > }
> >
> > v <- funB()
> > cat (v)
> > #2
> >
> > Or use <<- assignment I think.  (I usually return, but return can only
> > return one object and I think you want two or more
> >
> > v <- 1
> > funC <- function() {
> > v <<- v+1
> > }
> >
> > funC()
> > cat (v)
> > #2
> >
> > On Fri, 9 Aug 2024, 09:03 Steven Yen,  wrote:
> >
> > > Thanks. Hmm. The loop is doing what it is supposed to do.
> > >
> > > > try1<-function(joint12=FALSE,marg1=FALSE,marg2=FALSE,
> > > +cond12=FALSE,cond21=FALSE){
> > > + # ***
> > > + # Testing if loop
> > > + # ***
> > > + if(joint12){
> > > +   {print ("joint12"); cat(joint12,"\n")}
> > > +   {print ("marg1"); cat(marg1,"\n")}
> > > + } else if (marg1) {
> > > +   {print ("marg1"); cat(marg1,"\n")}
> > > +   {print ("joint12"); cat(joint12)}
> > > + } else if (marg2) {
> > > +   {print ("marg2"); cat(marg2)}
> > > + } else if (cond12) {
> > > +   {print ("cond12"); cat(cond12)}
> > > + } else {
> > > +   {print ("cond21"); cat(cond21)}
> > > + }}
> > > > try1(joint12=TRUE)
> > > [1] "joint12"
> > > TRUE
> > > [1] "marg1"
> > > FALSE
> > > > try1(marg1=TRUE)
> > > [1] "marg1"
> > > TRUE
> > > [1] "joint12"
> > > FALSE
> > > > try1(marg2=TRUE)
> > > [1] "marg2"
> > > TRUE
> > > > try1(cond12=TRUE)
> > > [1] "cond12"
> > > TRUE
> > > > try1(cond21=TRUE)
> > > [1] "cond21"
> > > TRUE
> > > >
> > > On 8/9/2024 2:35 PM, CALUM POLWART wrote:
> > >
> > > Is something wrong in the initialisation part that we don't see?
> > >
> > > joint12 <- marg1 <-F
> > >
> > > marg1 <-T
> > >
> > > if (joint12) {
> > >   print ("joint 12")
> > >   cat (joint12)
> > > }
> > >
> > > if (marg1) {
> > >   print("marg 1")
> > >   cat(marg1)
> > > }
> > >
> > > Would probably be my diagnostic approach
> > >
> > > On Fri, 9 Aug 2024, 04:45 Steven Yen,  wrote:
> > >
> > >> Can someone help me with the if loop below? In the subroutine, I
> > >> initialize all of (joint12,marg1,marg2,cond12,cond21) as FALSE, and
> call
> > >> with only one of them being TRUE:
> > >>
> > >>
> ,...,joint12=FALSE,marg1=FALSE,marg2=FALSE,cond12=FALSE,cond21=FALSE
> > >>
> > >> joint12 seems to always kick in, even though I call with, e.g., marg1
> > >> being TRUE and everything else being FALSE. My attempts with if...
> else
> > >> if were not useful. Please help. Thanks.
> > >>
> > >> v1<-cprob(z1,x1,a,b,mu1,mu2,rho,j+1,k+1)
> > >>  v0<-cprob(z0,x0,a,b,mu1

Re: [R] If loop

2024-08-09 Thread CALUM POLWART
OK. The fact it's in a function is making things clearer.

Are you trying to update the values of an object from within the function,
and have them available outside the function. I don't speak functional
programming articulately enough but basically

v <- 1

funA <- function() {
v <- v+1
}

funA()
cat (v)

# 1

You either return the v from the function so

funB <- function() {
v <- v+1
return (v)
}

v <- funB()
cat (v)
#2

Or use <<- assignment I think.  (I usually return, but return can only
return one object and I think you want two or more

v <- 1
funC <- function() {
v <<- v+1
}

funC()
cat (v)
#2

On Fri, 9 Aug 2024, 09:03 Steven Yen,  wrote:

> Thanks. Hmm. The loop is doing what it is supposed to do.
>
> > try1<-function(joint12=FALSE,marg1=FALSE,marg2=FALSE,
> +cond12=FALSE,cond21=FALSE){
> + # ***
> + # Testing if loop
> + # ***
> + if(joint12){
> +   {print ("joint12"); cat(joint12,"\n")}
> +   {print ("marg1"); cat(marg1,"\n")}
> + } else if (marg1) {
> +   {print ("marg1"); cat(marg1,"\n")}
> +   {print ("joint12"); cat(joint12)}
> + } else if (marg2) {
> +   {print ("marg2"); cat(marg2)}
> + } else if (cond12) {
> +   {print ("cond12"); cat(cond12)}
> + } else {
> +   {print ("cond21"); cat(cond21)}
> + }}
> > try1(joint12=TRUE)
> [1] "joint12"
> TRUE
> [1] "marg1"
> FALSE
> > try1(marg1=TRUE)
> [1] "marg1"
> TRUE
> [1] "joint12"
> FALSE
> > try1(marg2=TRUE)
> [1] "marg2"
> TRUE
> > try1(cond12=TRUE)
> [1] "cond12"
> TRUE
> > try1(cond21=TRUE)
> [1] "cond21"
> TRUE
> >
> On 8/9/2024 2:35 PM, CALUM POLWART wrote:
>
> Is something wrong in the initialisation part that we don't see?
>
> joint12 <- marg1 <-F
>
> marg1 <-T
>
> if (joint12) {
>   print ("joint 12")
>   cat (joint12)
> }
>
> if (marg1) {
>   print("marg 1")
>   cat(marg1)
> }
>
> Would probably be my diagnostic approach
>
> On Fri, 9 Aug 2024, 04:45 Steven Yen,  wrote:
>
>> Can someone help me with the if loop below? In the subroutine, I
>> initialize all of (joint12,marg1,marg2,cond12,cond21) as FALSE, and call
>> with only one of them being TRUE:
>>
>> ,...,joint12=FALSE,marg1=FALSE,marg2=FALSE,cond12=FALSE,cond21=FALSE
>>
>> joint12 seems to always kick in, even though I call with, e.g., marg1
>> being TRUE and everything else being FALSE. My attempts with if... else
>> if were not useful. Please help. Thanks.
>>
>> v1<-cprob(z1,x1,a,b,mu1,mu2,rho,j+1,k+1)
>>  v0<-cprob(z0,x0,a,b,mu1,mu2,rho,j+1,k+1)
>>
>> ...
>>
>>  me1<-me0<-NULL
>>  if(joint12) {me1<-cbind(me1,v1$p12); me0<-cbind(me0,v0$p12)}
>>  if(marg1)   {me1<-cbind(me1,v1$p1); me0<-cbind(me0,v0$p1)}
>>  if(marg2)   {me1<-cbind(me1,v1$p2); me0<-cbind(me0,v0$p2)}
>>  if(cond12)  {me1<-cbind(me1,v1$pc12); me0<-cbind(me0,v0$pc12)}
>>  if(cond21)  {me1<-cbind(me1,v1$pc21); me0<-cbind(me0,v0$pc21)}
>>  ...
>>
>>labels<-NULL
>>if(joint12) labels<-c(labels,lab.p12)
>>if(marg1)   labels<-c(labels,lab.p1)
>>if(marg2)   labels<-c(labels,lab.p2)
>>if(cond12)  labels<-c(labels,lab.pc12)
>>if(cond21)  labels<-c(labels,lab.pc21)
>>
>> __
>> 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] If loop

2024-08-08 Thread CALUM POLWART
Is something wrong in the initialisation part that we don't see?

joint12 <- marg1 <-F

marg1 <-T

if (joint12) {
  print ("joint 12")
  cat (joint12)
}

if (marg1) {
  print("marg 1")
  cat(marg1)
}

Would probably be my diagnostic approach

On Fri, 9 Aug 2024, 04:45 Steven Yen,  wrote:

> Can someone help me with the if loop below? In the subroutine, I
> initialize all of (joint12,marg1,marg2,cond12,cond21) as FALSE, and call
> with only one of them being TRUE:
>
> ,...,joint12=FALSE,marg1=FALSE,marg2=FALSE,cond12=FALSE,cond21=FALSE
>
> joint12 seems to always kick in, even though I call with, e.g., marg1
> being TRUE and everything else being FALSE. My attempts with if... else
> if were not useful. Please help. Thanks.
>
> v1<-cprob(z1,x1,a,b,mu1,mu2,rho,j+1,k+1)
>  v0<-cprob(z0,x0,a,b,mu1,mu2,rho,j+1,k+1)
>
> ...
>
>  me1<-me0<-NULL
>  if(joint12) {me1<-cbind(me1,v1$p12); me0<-cbind(me0,v0$p12)}
>  if(marg1)   {me1<-cbind(me1,v1$p1); me0<-cbind(me0,v0$p1)}
>  if(marg2)   {me1<-cbind(me1,v1$p2); me0<-cbind(me0,v0$p2)}
>  if(cond12)  {me1<-cbind(me1,v1$pc12); me0<-cbind(me0,v0$pc12)}
>  if(cond21)  {me1<-cbind(me1,v1$pc21); me0<-cbind(me0,v0$pc21)}
>  ...
>
>labels<-NULL
>if(joint12) labels<-c(labels,lab.p12)
>if(marg1)   labels<-c(labels,lab.p1)
>if(marg2)   labels<-c(labels,lab.p2)
>if(cond12)  labels<-c(labels,lab.pc12)
>if(cond21)  labels<-c(labels,lab.pc21)
>
> __
> 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] Extract

2024-07-22 Thread CALUM POLWART
But have we lured you to the dark side with the tidyverse yet ;-)



On Mon, 22 Jul 2024, 15:22 Bert Gunter,  wrote:

> Thanks.
>
> I found this to be quite informative and a nice example of how useful
> R-Help can be as a resource for R users.
>
> Best,
> Bert
>
> On Mon, Jul 22, 2024 at 4:50 AM Gabor Grothendieck
>  wrote:
> >
> > Base R. Regarding code improvements:
> >
> > 1. Personally I find (\(...) ...)() notation hard to read (although by
> > placing (\(x), the body and )() on 3 separate lines it can be improved
> > somewhat). Instead let us use a named function. The name of the
> > function can also serve to self document the code.
> >
> > 2. The use of dat both at the start of the pipeline and then again
> > within a later step of the pipeline goes against a strict left to
> > right flow. In general if this occurs it is either a sign that we need
> > to break the pipeline into two or that we need to find another
> > approach which is what we do here.
> >
> > We can use the base R code below. Note that the column names produced
> > by transform(S = read.table(...)) are S.V1, S.V2, etc. so to fix the
> > column names remove .V from all column names as in the fix_colnames
> > function shown. It does no harm to apply that to all column names
> > since the remaining column names will not match.
> >
> >   fix_colnames <- function(x) {
> > setNames(x, sub("\\.V", "", names(x)))
> >   }
> >
> >   dat |>
> >  transform(S = read.table(text = string,
> >header = FALSE, fill = TRUE, na.strings = "")) |>
> >fix_colnames()
> >
> > Another way to write this which does not use a separate defined
> > function nor the anonymous function notation is to box the output of
> > transform:
> >
> >   dat |>
> >  transform(S = read.table(text = string,
> >header = FALSE, fill = TRUE, na.strings = "")) |>
> >list(x = _) |>
> >with( setNames(x, sub("\\.V", "", names(x))) )
> >
> > dplyr. Alternately use dplyr in which case we can make use of
> > rename_with . In this case read.table(...) creates column names V1,
> > V2, etc. and mutate does not change them so simply replacing V with S
> > at the start of each column name in the output of read.table will do.
> > Also we can pipe the read.table output directly to rename_with using a
> > nested pipeline, i.e. the second pipe is entirely within mutate rather
> > than after it) since mutate won't change the column names. The win
> > here is because, unlike transform, mutate does not require the S= that
> > is needed with transform (although it allows it had we wanted it).
> >
> >   library(dplyr)
> >
> >   dat |>
> >  mutate(read.table(text = string,
> >header = FALSE, fill = TRUE, na.strings = "")  |>
> >   rename_with(~ sub("^V", "S", .x))
> > )
> >
> >
> > On Sun, Jul 21, 2024 at 3:08 PM Bert Gunter 
> wrote:
> > >
> > > As always, good point.
> > > Here's a piped version of your code for those who are pipe
> > > afficianados. As I'm not very skilled with pipes, it might certainly
> > > be improved.
> > > dat <-
> > >   dat$string |>
> > >  read.table( text = _, fill = TRUE, header = FALSE, na.strings
> = "")  |>
> > >  (\(x)'names<-'(x,paste0("s", seq_along(x() |>
> > >  (\(x)cbind(dat, x))()
> > >
> > > -- Bert
> > >
> > >
> > > On Sun, Jul 21, 2024 at 11:30 AM Gabor Grothendieck
> > >  wrote:
> > > >
> > > > Fixing col.names=paste0("S", 1:5) assumes that there will be 5
> columns and
> > > > we may not want to do that.  If there are only 3 fields in string,
> at the most,
> > > > we may wish to generate only 3 columns.
> > > >
> > > > On Sun, Jul 21, 2024 at 2:20 PM Bert Gunter 
> wrote:
> > > > >
> > > > > Nice! -- Let read.table do the work of handling the NA's.
> > > > > However, even simpler is to use the 'colnames' argument of
> > > > > read.table() for the column names no?
> > > > >
> > > > >   string <- read.table(text = dat$string, fill = TRUE, header =
> > > > > FALSE, na.strings = "",
> > > > > col.names = paste0("s", 1:5))
> > > > >   dat <- cbind(dat, string)
> > > > >
> > > > > -- Bert
> > > > >
> > > > > On Sun, Jul 21, 2024 at 10:16 AM Gabor Grothendieck
> > > > >  wrote:
> > > > > >
> > > > > > We can use read.table for a base R solution
> > > > > >
> > > > > > string <- read.table(text = dat$string, fill = TRUE, header =
> FALSE,
> > > > > > na.strings = "")
> > > > > > names(string) <- paste0("S", seq_along(string))
> > > > > > cbind(dat[-3], string)
> > > > > >
> > > > > > On Fri, Jul 19, 2024 at 12:52 PM Val  wrote:
> > > > > > >
> > > > > > > Hi All,
> > > > > > >
> > > > > > > I want to extract new variables from a string and add it to
> the dataframe.
> > > > > > > Sample data is csv file.
> > > > > > >
> > > > > > > dat<-read.csv(text="Year, Sex,string
> > > > > > > 2002,F,15 xc Ab
> > > > > > > 2003,F,14
> > > > > > > 2004,M,18 xb 25 35 21
> > > > > > > 2005,M,13 25
> > > > > > > 2006,M,14 ac 256 AV 35
> > > > > > > 2007,F,11",header=TRUE

Re: [R] Using the pipe, |>, syntax with "names<-"

2024-07-21 Thread CALUM POLWART
The tidy solution is rename

literally:

z |> rename(foo = 2)

Or you could do it with other functions

z |> select ( 1, foo = 2)

Or

z |> mutate( foo = 2 ) |> # untested (always worry that makes the whole
column 2)
select (-2)

But that's akin to

z$foo <- z[2]
z[2] <- null

On Sun, 21 Jul 2024, 16:01 Bert Gunter,  wrote:

> Wow!
> Yes, this is very clever -- way too clever for me -- and meets my
> criteria for a solution.
>
> I think it's also another piece of evidence of why piping in base R is
> not suited for complex/nested assignments, as discussed in Deepayan's
> response.
>
> Maybe someone could offer a better Tidydata piping solution just for
> completeness?
>
> Best,
> Bert
>
> On Sun, Jul 21, 2024 at 7:48 AM Gabor Grothendieck
>  wrote:
> >
> > This
> > - is non-destructive (does not change z)
> > - passes the renamed z onto further pipe legs
> > - does not use \(x)...
> >
> > It works by boxing z, operating on the boxed version and then unboxing
> it.
> >
> >   z <- data.frame(a = 1:3, b = letters[1:3])
> >   z |> list(x = _) |> within(names(x)[2] <- "foo") |> _$x
> >   ##   a foo
> >   ## 1 1   a
> >   ## 2 2   b
> >   ## 3 3   c
> >
> > On Sat, Jul 20, 2024 at 4:07 PM Bert Gunter 
> wrote:
> > >
> > > This post is likely pretty useless;  it is motivated by a recent post
> > > from "Val" that was elegantly answered using Tidyverse constructs, but
> > > I wondered how to do it using base R only. Along the way, I ran into
> > > the following question to which I think my answer (below) is pretty
> > > awful. I would be interested in more elegant base R approaches. So...
> > >
> > > z <- data.frame(a = 1:3, b = letters[1:3])
> > > > z
> > >   a h
> > > 1 1 a
> > > 2 2 b
> > > 3 3 c
> > >
> > > Suppose I want to change the name of the second column of z from 'b'
> > > to 'foo' . This is very easy using nested function syntax by:
> > >
> > > names(z)[2] <- "foo"
> > > > z
> > >   a foo
> > > 1 1   a
> > > 2 2   b
> > > 3 3   c
> > >
> > > Now suppose I wanted to do this using |> syntax, along the lines of:
> > >
> > > z |> names()[2] <- "foo"  ## throws an error
> > >
> > > Slightly fancier is:
> > >
> > > z |> (\(x)names(x)[2] <- "b")()
> > > ## does nothing, but does not throw an error.
> > >
> > > However, the following, which resulted from a more careful read of
> > > ?names works (after changing the name of the second column back to "b"
> > > of course):
> > >
> > > z |>(\(x) "names<-"(x,value = "[<-"(names(x),2,'foo')))()
> > > >z
> > >   a foo
> > > 1 1   a
> > > 2 2   b
> > > 3 3   c
> > >
> > > This qualifies to me as "pretty awful." I'm sure there are better ways
> > > to do this using pipe syntax, so I would appreciate any better
> > > approaches.
> > >
> > > Best,
> > > Bert
> > >
> > > __
> > > 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.
> >
> >
> >
> > --
> > Statistics & Software Consulting
> > GKX Group, GKX Associates Inc.
> > tel: 1-877-GKX-GROUP
> > email: ggrothendieck at gmail.com
>
> __
> 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] my R code worked well when running the first 1000 lines of R code

2024-06-12 Thread CALUM POLWART
I sometimes think people on this list are quite rude to posters.

I'm afraid I'm likely to join in with some rudeness?

1. "Here is some code that works but also doesn't" is probably not going to
get you an answer
2. I provide no information about the data it works on or doesn't
3. I tell you I'm using a load of dependencies, but don't tell you what
4. I refer to 2000 lines of code but probably means 2000 lines of data?

So. Please post a question someone can actually answer.

If the question is "why might code fail on a 2000 line dataset when it
works on 1000 line dataset" then here are some thoughts:

* Is the 1000 lines being run as dataset[1:1000,] or is it dataset1 and
dataset2 ?
* Is there a structural difference in the datasets - i.e. numbers,
characters or factors as columns. Often import functions guess a column
type by reading the first 500/1000 lines. If the data has numbers in column
1 for 1-1000 but on line 1999 has a letter... The data type may vary.

On Wed, 12 Jun 2024, 17:28 Yuan Chun Ding via R-help, 
wrote:

> Hi R users,
>
> The following code worked well to summarize four data groups in a
> dataframe for three variables (t_depth, t_alt_count, t_alt_ratio), 12
> columns of summary, see attached.
> However, after running another 2000 lines of R codes using functions from
> more than 10 other R  libraries, then it only generated one column of
> summary.
> Do you know why?
>
> Thank you,
>
> Yuan Chun Ding
>
> summary_anno1148ft <- anno1148ft %>%
>   pivot_longer(c(t_depth, t_alt_count, t_alt_ratio), names_to = "measure")
> %>%
>   group_by(dat, measure) %>%
>   summarize(minimum = min(value,na.rm=T),
> q25 = quantile(value, probs = 0.25,na.rm=T),
> med = median(value,na.rm=T),
> q75 = quantile(value, probs = 0.75,na.rm=T),
> maximum = max(value,na.rm=T),
> average = mean(value,na.rm=T),
> #standard_deviation = sd(value),
> .groups = "drop"
>   )
> summary_anno1148ft <-t(summary_anno1148ft)
>
>
>
> --
> 
> -SECURITY/CONFIDENTIALITY WARNING-
>
> This message and any attachments are intended solely for the individual or
> entity to which they are addressed. This communication may contain
> information that is privileged, confidential, or exempt from disclosure
> under applicable law (e.g., personal health information, research data,
> financial information). Because this e-mail has been sent without
> encryption, individuals other than the intended recipient may be able to
> view the information, forward it to others or tamper with the information
> without the knowledge or consent of the sender. If you are not the intended
> recipient, or the employee or person responsible for delivering the message
> to the intended recipient, any dissemination, distribution or copying of
> the communication is strictly prohibited. If you received the communication
> in error, please notify the sender immediately by replying to this message
> and deleting the message and any accompanying files from your system. If,
> due to the security risks, you do not wish to receive further
> communications via e-mail, please reply to this message and inform the
> sender that you do not wish to receive further e-mail from the sender.
> (LCP301)
> 
> __
> 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] Current version of R, 4.4.0 and patch to correct the bug fix related to the RStudio viewer pane on Windows systems

2024-05-16 Thread CALUM POLWART
Do you receive RDS objects from unknown (untrusted) sources?

?? If not - the security issue is a non-issue as I understand it.


On Thu, 16 May 2024, 16:21 Vega, Ann (she/her/hers) via R-help, <
r-help@r-project.org> wrote:

> I help to coordinate the USEPA's R user group.  We have over 500 members
> and our security officer has required us to update to R version 4.4.0
> because of the security vulnerability to versions prior.  However, we
> cannot download the patched version because it does not have a signed
> certificate and Microsoft Defender won't allow us to install it.
>
> Most of our users rely on the RStudio viewer pane so we are in a bit of a
> quandary.  We suspect other government agencies are impacted by this as
> well.
>
> Can you give me an estimated time for when another official version will
> be released with the patch included?  I may be able to ask our security
> officer to allow us to delay our install until that official version is
> released.  Alternatively, if the patched version could have a signed
> certificate, that would allow us to install it.
>
> Thank you.
>
> Ann Vega, PSPO
> She/Her/Hers (Learn More >)
> Office of Science Information Management, Data Architect
> EPA Office of Research and Development
> Cincinnati, OH
>
> Mobile: 513-418-1922 - or reach out to me on Teams!
> Hours:  Monday-Thursday, 7:30am - 6:00 pm, CDO:  Fridays
> Email: vega@epa.gov
>
>
>
> [[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.


Re: [R] Extracting values from Surv function in survival package

2024-05-16 Thread CALUM POLWART
I don't think that gives the summary of event numbers without extra work.

library(survival)
fit <- survfit( Surv(time,status)~sex,data=lung)
summary(fit)$n.event

[1] 3 1 2 1 1 1 1 2 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 3 1 1 1 1 1 2
 [38] 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1
 [75] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1
[112] 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
[149] 1 1


You can get something out using:

summary(fit)$table[,"events"]

sex=1 sex=2
  11253


But there are sub-options in the summary that might work.

summary(fit, times =1022, extend=T)$n.event

[1] 112  53



times=1022 is the maximum time in the lung dataset (you will need your
maximum) and extend=T, extends the other curves to that data point allowing
totals for events at that data point



On Thu, 16 May 2024, 08:53 Göran Broström,  wrote:

> Hi Dennis,
>
> look at the help page for summary.survfit, the Value n.event.
>
> Göran
>
> On 2024-05-15 22:41, Dennis Fisher wrote:
> > OS X
> > R 4.3.3
> >
> > Colleagues
> >
> > I have created objects using the Surv function in the survival package:
> >> FIT.1
> > Call: survfit(formula = FORMULA1)
> >
> > n events median 0.95LCL 0.95UCL
> > SUBDATA$ARM=1, SUBDATA[, EXP.STRAT]=0 18 13345 156  NA
> > SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=1 13  5 NA 186  NA
> > SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=2  5  5168  81  NA
> > SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=3  1  1 22  NA  NA
> >
> > I am interested in extracting the “n” and “events” values.
> > “n” is easy:
> >> FIT.1[[1]]
> > [1] 18 13  5  1
> >
> > or
> >> FIT.1$n
> > [1] 18 13  5  1
> >
> > But I can’t figure out how to access “events”.
> >
> > str(FIT.1) provides no insights:
> > List of 17
> >   $ n: int [1:4] 18 13 5 1
> >   $ time : num [1:37] 45 106 107 124 152 156 170 176 319 371 ...
> >   $ n.risk   : num [1:37] 18 17 16 15 14 13 12 11 10 9 ...
> >   $ n.event  : num [1:37] 1 1 1 1 1 1 1 1 1 1 ...
> >   $ n.censor : num [1:37] 0 0 0 0 0 0 0 0 0 0 ...
> >   $ surv : num [1:37] 0.944 0.889 0.833 0.778 0.722 ...
> >   $ std.err  : num [1:37] 0.0572 0.0833 0.1054 0.126 0.1462 ...
> >   $ cumhaz   : num [1:37] 0.0556 0.1144 0.1769 0.2435 0.315 ...
> >   $ std.chaz : num [1:37] 0.0556 0.0809 0.1022 0.1221 0.1414 ...
> >   $ strata   : Named int [1:4] 18 13 5 1
> >..- attr(*, "names")= chr [1:4] "SUBDATA$ARM=1, SUBDATA[,
> EXP.STRAT]=0" "SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=1" "SUBDATA$ARM=2,
> SUBDATA[, EXP.STRAT]=2" "SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=3"
> >   $ type : chr "right"
> >   $ logse: logi TRUE
> >   $ conf.int : num 0.95
> >   $ conf.type: chr "log"
> >   $ lower: num [1:37] 0.844 0.755 0.678 0.608 0.542 ...
> >   $ upper: num [1:37] 1 1 1 0.996 0.962 ...
> >   $ call : language survfit(formula = FORMULA1)
> >   - attr(*, "class")= chr "survfit"
> >
> > If I could access:
> > n events median 0.95LCL 0.95UCL
> > SUBDATA$ARM=1, SUBDATA[, EXP.STRAT]=0 18 13345 156  NA
> > SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=1 13  5 NA 186  NA
> > SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=2  5  5168  81  NA
> > SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=3  1  1 22  NA  NA
> > it should be easy to get “events”.
> >
> > Any thoughts?
> >
> > Dennis
> >
> > Dennis Fisher MD
> > P < (The "P Less Than" Company)
> > Phone / Fax: 1-866-PLessThan (1-866-753-7784)
> > www.PLessThan.com
> >
> > __
> > 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] Extracting values from Surv function in survival package

2024-05-15 Thread CALUM POLWART
More difficult than it should be IMO.

survminer package is often helpful. But if you want to avoid dependency:

library(survival)
fit <- survfit( Surv(time,status)~sex,data=lung)

surfable <-summary(fit)$table
surfable

# just the events
surfable[,"events"]

On Wed, 15 May 2024, 21:42 Dennis Fisher,  wrote:

> OS X
> R 4.3.3
>
> Colleagues
>
> I have created objects using the Surv function in the survival package:
> > FIT.1
> Call: survfit(formula = FORMULA1)
>
>n events median 0.95LCL 0.95UCL
> SUBDATA$ARM=1, SUBDATA[, EXP.STRAT]=0 18 13345 156  NA
> SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=1 13  5 NA 186  NA
> SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=2  5  5168  81  NA
> SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=3  1  1 22  NA  NA
>
> I am interested in extracting the “n” and “events” values.
> “n” is easy:
> > FIT.1[[1]]
> [1] 18 13  5  1
>
> or
> > FIT.1$n
> [1] 18 13  5  1
>
> But I can’t figure out how to access “events”.
>
> str(FIT.1) provides no insights:
> List of 17
>  $ n: int [1:4] 18 13 5 1
>  $ time : num [1:37] 45 106 107 124 152 156 170 176 319 371 ...
>  $ n.risk   : num [1:37] 18 17 16 15 14 13 12 11 10 9 ...
>  $ n.event  : num [1:37] 1 1 1 1 1 1 1 1 1 1 ...
>  $ n.censor : num [1:37] 0 0 0 0 0 0 0 0 0 0 ...
>  $ surv : num [1:37] 0.944 0.889 0.833 0.778 0.722 ...
>  $ std.err  : num [1:37] 0.0572 0.0833 0.1054 0.126 0.1462 ...
>  $ cumhaz   : num [1:37] 0.0556 0.1144 0.1769 0.2435 0.315 ...
>  $ std.chaz : num [1:37] 0.0556 0.0809 0.1022 0.1221 0.1414 ...
>  $ strata   : Named int [1:4] 18 13 5 1
>   ..- attr(*, "names")= chr [1:4] "SUBDATA$ARM=1, SUBDATA[, EXP.STRAT]=0"
> "SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=1" "SUBDATA$ARM=2, SUBDATA[,
> EXP.STRAT]=2" "SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=3"
>  $ type : chr "right"
>  $ logse: logi TRUE
>  $ conf.int : num 0.95
>  $ conf.type: chr "log"
>  $ lower: num [1:37] 0.844 0.755 0.678 0.608 0.542 ...
>  $ upper: num [1:37] 1 1 1 0.996 0.962 ...
>  $ call : language survfit(formula = FORMULA1)
>  - attr(*, "class")= chr "survfit"
>
> If I could access:
>n events median 0.95LCL 0.95UCL
> SUBDATA$ARM=1, SUBDATA[, EXP.STRAT]=0 18 13345 156  NA
> SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=1 13  5 NA 186  NA
> SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=2  5  5168  81  NA
> SUBDATA$ARM=2, SUBDATA[, EXP.STRAT]=3  1  1 22  NA  NA
> it should be easy to get “events”.
>
> Any thoughts?
>
> Dennis
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone / Fax: 1-866-PLessThan (1-866-753-7784)
> www.PLessThan.com
>
> __
> 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] Exceptional slowness with read.csv

2024-04-08 Thread CALUM POLWART
data.table's fread is also fast. Not sure about error handling. But I can
merge 300 csvs with a total of 0.5m lines and 50 columns in a couple of
minutes versus a lifetime with read.csv or readr::read_csv



On Mon, 8 Apr 2024, 16:19 Stevie Pederson, 
wrote:

> Hi Dave,
>
> That's rather frustrating. I've found vroom (from the package vroom) to be
> helpful with large files like this.
>
> Does the following give you any better luck?
>
> vroom(file_name, delim = ",", skip = 2459465, n_max = 5)
>
> Of course, when you know you've got errors & the files are big like that it
> can take a bit of work resolving things. The command line tools awk & sed
> might even be a good plan for finding lines that have errors & figuring out
> a fix, but I certainly don't envy you.
>
> All the best
>
> Stevie
>
> On Tue, 9 Apr 2024 at 00:36, Dave Dixon  wrote:
>
> > Greetings,
> >
> > I have a csv file of 76 fields and about 4 million records. I know that
> > some of the records have errors - unmatched quotes, specifically.
> > Reading the file with readLines and parsing the lines with read.csv(text
> > = ...) is really slow. I know that the first 2459465 records are good.
> > So I try this:
> >
> >  > startTime <- Sys.time()
> >  > first_records <- read.csv(file_name, nrows = 2459465)
> >  > endTime <- Sys.time()
> >  > cat("elapsed time = ", endTime - startTime, "\n")
> >
> > elapsed time =   24.12598
> >
> >  > startTime <- Sys.time()
> >  > second_records <- read.csv(file_name, skip = 2459465, nrows = 5)
> >  > endTime <- Sys.time()
> >  > cat("elapsed time = ", endTime - startTime, "\n")
> >
> > This appears to never finish. I have been waiting over 20 minutes.
> >
> > So why would (skip = 2459465, nrows = 5) take orders of magnitude longer
> > than (nrows = 2459465) ?
> >
> > Thanks!
> >
> > -dave
> >
> > PS: readLines(n=2459470) takes 10.42731 seconds.
> >
> > __
> > 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.
>

[[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] Problem with R coding

2024-03-12 Thread CALUM POLWART
That's almost certainly going to be either the utf-8 character in the path
OR the use of one drive which isn't really a subfolder as I understand it.

When I've had these issues in the past, I've been able to mount a drive
(say U:/ ) which sites further down /up the folder tree so that R just
called "U:/RCodeFolder/Rfile.R"

Is that possible with an C drive?

On Tue, 12 Mar 2024, 10:40 Ivan Krylov via R-help, 
wrote:

> Dear Maria,
>
> I'm sorry for somehow completely missing the second half of your
> message where you say that you've already tried the workaround.
>
> В Tue, 12 Mar 2024 07:43:08 +
> Maria Del Mar García Zamora  пишет:
>
> > I have tried to start R from CDM using: C:\Users\marga>set
> > R_USER=C:\Users\marga\R_USER
> >
> > C:\Users\marga>"C:\Users\marga\Desktop\R-4.3.3\bin\R.exe" CMD Rgui
> >
> > At the beginning this worked but right now a message saying that this
> > app cannot be used and that I have to ask the software company (photo
> > attached)
>
> Glad to know the workaround helped. It sounds like your Windows
> 10 is set up in a user-hostile way.
>
> It may help to visit the Windows Security settings and make an
> exception for C:\Users\marga\Desktop\R-4.3.3\bin\R.exe. An approximate
> instruction can be found at
> , but it
> might be the case that your university IT must take a look at it before
> allowing you to run R on your computer.
>
> Feel free to disregard this advice if someone with more Windows
> experience shows up.
>
> --
> Best regards,
> Ivan
>
> __
> 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] Including an external set of coded

2024-02-20 Thread CALUM POLWART
What happens if you add a line to the code in lines 1-5.  So line 5 is now
line 6 etc?

Your "procedure" needs a name

So either it's a function, OR, we each procedure is a file to source?

On Tue, 20 Feb 2024, 16:55 Steven Yen,  wrote:

> I see——still put those lines in a procedure and call the procedure by
> “source”. I source procedures all the time.
>
> I just wondered whether there is a way to “source” these lines without
> putting them in a procedure. Because I have too many of such lines which I
> use in several main programs annd only reason I want to do this is to keep
> my main programs compact.
>
> Steven from iPhone
>
> On Feb 21, 2024, at 12:44 AM, CALUM POLWART  wrote:
>
> 
> Are you asking to source lines 5-10 of a file for instance?
>
> Never seen that done in R. Feels a dodgy thing to do as changing line will
> screw things up.  On the other hand - I'd often have functions in a file
> called perhaps "functions.R" and source("functions.R")
>
> Then I can call an individual function something like
>
> tranform_mydata(mydata)
>
>
>
> With the functions.R containing
>
> transform_mydata <- function (mydata) {
>
> mydata<-transform(mydata,
> a<-b+c
> d<-e+f
>
> return(mydata)
> }
>
> On Tue, 20 Feb 2024, 15:46 Bert Gunter,  wrote:
>
>> I believe you will have to expain what you want more fully, as what you
>> requested appears to be exactly what source() does, to me anyway. Please
>> reread its help file more carefully perhaps?
>>
>> -- Bert
>>
>> On Tue, Feb 20, 2024 at 7:36 AM Steven Yen  wrote:
>>
>> > How can I call and include an external set of R codes, not necessarily a
>> > complete procedure (which can be include with a “source” command).
>> Example:
>> >
>> > #I like to include and run the following lines residing in a file
>> outside
>> > the main program:
>> >
>> > mydata<-transform(mydata,
>> > a<-b+c
>> > d<-e+f
>> > }
>> >
>> >
>> > Steven from iPhone
>> > [[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.
>>
>

[[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 an external set of coded

2024-02-20 Thread CALUM POLWART
Are you asking to source lines 5-10 of a file for instance?

Never seen that done in R. Feels a dodgy thing to do as changing line will
screw things up.  On the other hand - I'd often have functions in a file
called perhaps "functions.R" and source("functions.R")

Then I can call an individual function something like

tranform_mydata(mydata)



With the functions.R containing

transform_mydata <- function (mydata) {

mydata<-transform(mydata,
a<-b+c
d<-e+f

return(mydata)
}

On Tue, 20 Feb 2024, 15:46 Bert Gunter,  wrote:

> I believe you will have to expain what you want more fully, as what you
> requested appears to be exactly what source() does, to me anyway. Please
> reread its help file more carefully perhaps?
>
> -- Bert
>
> On Tue, Feb 20, 2024 at 7:36 AM Steven Yen  wrote:
>
> > How can I call and include an external set of R codes, not necessarily a
> > complete procedure (which can be include with a “source” command).
> Example:
> >
> > #I like to include and run the following lines residing in a file outside
> > the main program:
> >
> > mydata<-transform(mydata,
> > a<-b+c
> > d<-e+f
> > }
> >
> >
> > Steven from iPhone
> > [[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.
>

[[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] Avoiding Delete key function as 'Quit R' in Rterm when there are no characters in cursor line

2024-02-09 Thread CALUM POLWART
I don't use term, but I've just tested it and this is reproducable.

Is it a bug? Not sure. If you hit c after getting the message it will
cancel the q() request.


On Fri, 9 Feb 2024, 17:21 Duncan Murdoch,  wrote:

> That looks to me like a bug, but I don't use Windows any more, so I
> won't offer to try to fix it for you.  In fact I don't think Rterm has
> many users at all:  most Windows users probably use RStudio or one of
> the other graphical front ends (Visual Studio, Emacs, Rgui, etc.)
>
> So maybe you can track down the issue, or someone else will try.  Or
> maybe you'll just have to avoid triggering the bug (if it really is one).
>
> Duncan Murdoch
>
> On 09/02/2024 10:03 a.m., Iago Giné Vázquez wrote:
> > Yes, indeed, I am talking about Rterm in Windows.
> >
> > Iago
> > 
> > *De:* Duncan Murdoch 
> > *Enviat el:* divendres, 9 de febrer de 2024 13:50
> > *Per a:* Iago Giné Vázquez 
> > *Tema:* Re: [R] Avoiding Delete key function as 'Quit R' in Rterm when
> > there are no characters in cursor line
> > On 09/02/2024 6:25 a.m., Iago Giné Vázquez wrote:
> >> Hi all,
> >>
> >> I cite from README.Rterm
> >>
> >> ^D, DEL : Delete the character under the cursor.
> >>
> >> That is the general behaviour, but when there is no character (neither
> under the cursor nor at its left), pressing the Delete key suggests closing
> the R terminal. Is there any (configurable) way to avoid this behaviour?
> >
> > Are you talking about rterm in Windows, or which front end?
> >
> > Duncan Murdoch
> >
>
> __
> 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] R interpreting numeric field as a boolean field

2024-01-30 Thread CALUM POLWART
And your other option - recode what gets imported. It may well be you will
actually want the blanks to be NAs for instance rather than blank. I'm
assuming the True and False are >$0 and $0 from your description. (Or maybe
vice versa). So I'd have made my column name something like
"OverZeroDollars" and then your data makes sense... Depends what data
processing comes next.

On Tue, 30 Jan 2024, 19:41 Duncan Murdoch,  wrote:

> If you are using the read_excel() function from the readxl package, then
> there's an argument named col_types that lets you specify the types to use.
>
> You could specify col_types = "numeric" to read all columns as numeric
> columns.  If some columns are different types, you should specify a
> vector of type names, with one entry per column.  Allowable names are
> "skip", "guess", "logical", "numeric", "date", "text" or "list".  You'll
> have to read the docs to find out what some of those do.
>
> Duncan Murdoch
>
> On 30/01/2024 1:40 p.m., Paul Bernal wrote:
> > Dear friend Duncan,
> >
> > Thank you so much for your kind reply. Yes, that is exactly what is
> > happening, there are a lot of NA values at the start, so R assumes that
> > the field is of type boolean. The challenge that I am facing is that I
> > want to read into R an Excel file that has many sheets (46 in this case)
> > but I wanted to combine all 46 sheets into a single dataframe (since the
> > columns are exactly the same for all 46 sheets). The rio package does
> > this nicely, the problem is that, once I have the full dataframe (which
> > amounts to roughly 2.98 million rows total), I cannot change the data
> > type from boolean to numeric. I tried doing dataset$my_field =
> > as.numeric(dataset$my_field), I also tried to do dataset <-
> > dataset[complete.cases(dataset), ], didn't work either.
> >
> > The only thing that worked for me was to take a single sheed and through
> > the read_excel function use the guess_max parameter and set it to a
> > sufficiently large number (a number >= to the total amount of the full
> > merged dataset). I want to automate the merging of the N number of Excel
> > sheets so that I don't have to be manually doing it. Unless there is a
> > way to accomplish something similar to what rio's package function
> > import_list does, that is able to keep the field's numeric data type
> nature.
> >
> > Cheers,
> > Paul
> >
> > El mar, 30 ene 2024 a las 12:23, Duncan Murdoch
> > (mailto:murdoch.dun...@gmail.com>>) escribió:
> >
> > On 30/01/2024 11:10 a.m., Paul Bernal wrote:
> >  > Dear friends,
> >  >
> >  > Hope you are doing well. I am currently using R version 4.3.2,
> > and I have a
> >  > .xlsx file that has 46 sheets on it. I basically combined  all 46
> > sheets
> >  > and read them as a single dataframe in R using package rio.
> >  >
> >  > I read a solution using package readlx, as suggested in a
> > StackOverflow
> >  > discussion as follows:
> >  > df <- read_excel(path = filepath, sheet = sheet_name, guess_max =
> > 10).
> >  > Now, when you have so many sheets (46 in my case) in an Excel
> > file, the rio
> >  > methodology is more practical.
> >  >
> >  > This is what I did:
> >  > path =
> >  >
> >
>  
> "C:/Users/myuser/Documents/DataScienceF/Forecast_and_Econometric_Analysis_FIGI
> >  > (4).xlsx"
> >  > figidat = import_list(path, rbind = TRUE) #here figidat refers to
> > my dataset
> >  >
> >  > Now, it successfully imports and merges all records, however,
> > some fields
> >  > (despite being numeric), R interprets as a boolean field.
> >  >
> >  > Here is the structure of the field that is causing me problems (I
> > apologize
> >  > for the length):
> >  > structure(list(StoreCharges = c(NA, NA, NA, NA, NA, NA, NA, NA,
> >  > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >  > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >  > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >  > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >  > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >  > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >  > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> >  > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> > ...
> >  > FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NA, NA,
> >  > FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
> >  > FALSE, FALSE, FALSE)), class = c("tbl_df", "tbl", "data.frame"
> >  > ), row.names = c(NA, -7033L))
> >  >
> >  > As you can see, when I do the dput, it gives me a bunch of TRUE
> > and FALSE
> >  > values, when in reality I have records with value $0, records
> > with amounts
> >  >> $0 and also a bunch of blank records.
> >  >
> >

Re: [R] Help request: Parsing docx files for key words and appending to a spreadsheet

2023-12-29 Thread CALUM POLWART
help(read_docx) says that the function only imports one docx file. In
> order to read multiple files, use a for loop or the lapply function.
>

I told you people will suggest better ways to loop!!


>
> docx_summary(read_docx("Now they want us to charge our electric cars
> from litter bins.docx")) should work.
>

Ivan thanks for spotting my fail! Since the OP is new to all this I'm going
to suggest a little tweak to this code which we can then build into a for
loop:

filepath <- getwd() #you will want to change this later. You are doing
something with tcl to pick a directory which seems rather fancy! But keep
doing it for now or set the directory here ending in a /

filename <- "Now they want us to charge our electric cars from litter
bins.docx"

full_filename <- paste0(filepath, filename)

#lets double check the file does exist!
if (!file.exists(full_filename)) {
  message("File missing")
} else {
  content <- read_docx(full_filename) |>
docx_summary()
# this reads docx for the full filename and
# passes it ( |> command) to the next line
# which summarises it.
# the result is saved in a data frame object
# called content which we shall show some
# heading into from

   head(content)
}

Let's get this bit working before we try and loop

>

[[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] Help request: Parsing docx files for key words and appending to a spreadsheet

2023-12-29 Thread CALUM POLWART
It sounded like he looked at officeR but I would agree

content <- officer::docx_summary("filename.docx")

Would get the text content into an object called content.

That object is a data.frame so you can then manipulate it.  To be more
specific, we might need an example of the DF

You can loop this easily with a for statement although there are people who
prefer a non-for approach to iteration in R. For can be slow. But if you
don't need to do this very quickly I'd stick with for if you are used to
programming

On Fri, 29 Dec 2023, 18:35 jim holtman,  wrote:

> checkout the 'officer' package
>
> Thanks
>
> 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 Fri, Dec 29, 2023 at 10:14 AM Andy  wrote:
>
> > Hello
> >
> > I am trying to work through a problem, but feel like I've gone down a
> > rabbit hole. I'd very much appreciate any help.
> >
> > The task: I have several directories of multiple (some directories, up
> > to 2,500+) *.docx files (newspaper articles downloaded from Lexis+) that
> > I want to iterate through to append to a spreadsheet only those articles
> > that satisfy a condition (i.e., a specific keyword is present for >= 50%
> > coverage of the subject matter). Lexis+ has a very specific structure
> > and keywords are given in the row "Subject".
> >
> > I'd like to be able to accomplish the following:
> >
> > (1) Append the title, the month, the author, the number of words, and
> > page number(s) to a spreadsheet
> >
> > (2) Read each article and extract keywords (in the docs, these are
> > listed in 'Subject' section as a list of keywords with a percentage
> > showing the extent to which the keyword features in the article (e.g.,
> > FAST FASHION (72%)) and to append the keyword and the % coverage to the
> > same row in the spreadsheet. However, I want to ensure that the keyword
> > coverage meets the threshold of >= 50%; if not, then pass onto the next
> > article in the directory. Rinse and repeat for the entire directory.
> >
> > So far, I've tried working through some Stack Overflow-based solutions,
> > but most seem to use the textreadr package, which is now deprecated;
> > others use either the officer or the officedown packages. However, these
> > packages don't appear to do what I want the program to do, at least not
> > in any of the examples I have found, nor in the vignettes and relevant
> > package manuals I've looked at.
> >
> > The first point is, is what I am intending to do even possible using R?
> > If it is, then where do I start with this? If these docx files were
> > converted to UTF-8 plain text, would that make the task easier?
> >
> > I am not a confident coder, and am really only just getting my head
> > around R so appreciate a steep learning curve ahead, but of course, I
> > don't know what I don't know, so any pointers in the right direction
> > would be a big help.
> >
> > Many thanks in anticipation
> >
> > Andy
> >
> > __
> > 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.
>

[[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] Help request: Parsing docx files for key words and appending to a spreadsheet

2023-12-29 Thread CALUM POLWART
textreadr would be the obvious approach.

When you say it is depreciated do you mean it's not available on cran?
Sometimes maintaining a package on cran in just a pain in the ass.

devtools::install_github("trinker/textreadr")


Should let you install it.

In theory docx files are actually just zip files (you can unzip them) and
you may find there is then a specific file in the zip that is readable with
on of R's General text file readers.

Alternatively, read_docx from:
https://www.rdocumentation.org/packages/qdapTools

May be worth a look.

What platform are you on. Certainly options to command line convert files
to txt and do from there.


On Fri, 29 Dec 2023, 18:25 Roy Mendelssohn - NOAA Federal via R-help, <
r-help@r-project.org> wrote:

> Hi Andy:
>
> I don’t have an answer but I do have what I hope is some friendly advice.
> Generally the more information you can provide,  the more likely you will
> get help that is useful.  In your case you say that you tried several
> packages and they didn’t do what you wanted.  Providing that code,  as well
> as why they didn’t do what you wanted (be specific)  would greatly
> facilitate things.
>
> Happy new year,
>
> -Roy
>
>
> > On Dec 29, 2023, at 10:14 AM, Andy  wrote:
> >
> > Hello
> >
> > I am trying to work through a problem, but feel like I've gone down a
> rabbit hole. I'd very much appreciate any help.
> >
> > The task: I have several directories of multiple (some directories, up
> to 2,500+) *.docx files (newspaper articles downloaded from Lexis+) that I
> want to iterate through to append to a spreadsheet only those articles that
> satisfy a condition (i.e., a specific keyword is present for >= 50%
> coverage of the subject matter). Lexis+ has a very specific structure and
> keywords are given in the row "Subject".
> >
> > I'd like to be able to accomplish the following:
> >
> > (1) Append the title, the month, the author, the number of words, and
> page number(s) to a spreadsheet
> >
> > (2) Read each article and extract keywords (in the docs, these are
> listed in 'Subject' section as a list of keywords with a percentage showing
> the extent to which the keyword features in the article (e.g., FAST FASHION
> (72%)) and to append the keyword and the % coverage to the same row in the
> spreadsheet. However, I want to ensure that the keyword coverage meets the
> threshold of >= 50%; if not, then pass onto the next article in the
> directory. Rinse and repeat for the entire directory.
> >
> > So far, I've tried working through some Stack Overflow-based solutions,
> but most seem to use the textreadr package, which is now deprecated; others
> use either the officer or the officedown packages. However, these packages
> don't appear to do what I want the program to do, at least not in any of
> the examples I have found, nor in the vignettes and relevant package
> manuals I've looked at.
> >
> > The first point is, is what I am intending to do even possible using R?
> If it is, then where do I start with this? If these docx files were
> converted to UTF-8 plain text, would that make the task easier?
> >
> > I am not a confident coder, and am really only just getting my head
> around R so appreciate a steep learning curve ahead, but of course, I don't
> know what I don't know, so any pointers in the right direction would be a
> big help.
> >
> > Many thanks in anticipation
> >
> > Andy
> >
> > __
> > 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] adding "Page X of XX" to PDFs

2023-12-02 Thread CALUM POLWART
You could easily omit the Page X of xX, but leave the timestamp

Then add Page X of XX programmatically using pdftools or some similar pdf
command line tools.

On Sat, 2 Dec 2023, 22:35 ,  wrote:

> Having read all of the replies, it seems there are solutions for the
> question and the OP points out that some solutions such as making the
> document twice will affect the creation date.
>
> I suspect the additional time to do so is seconds or at most minutes so it
> may not be a big deal.
>
> But what about the idea of creating a PDF with a placeholder like "Page N
> of
> XXX" and after the file has been created, dates and all, perhaps edit it
> programmatically and replace all instances of XXX with something of the
> same
> length like " 23" as there seem to be tools like the pdftools package that
> let you get the number of pages. I have no idea if some program, perhaps
> external, can do that and retain the date you want.
>
> -Original Message-
> From: R-help  On Behalf Of Dennis Fisher
> Sent: Friday, December 1, 2023 3:53 PM
> To: r-help@r-project.org
> Subject: [R] adding "Page X of XX" to PDFs
>
> OS X
> R 4.3.1
>
> Colleagues
>
> I often create multipage PDFs [pdf()] in which the text "Page X" appears in
> the margin.  These PDFs are created automatically using a massive R script.
>
> One of my clients requested that I change this to:
> Page X of XX
> where XX is the total number of pages.
>
> I don't know the number of expected pages so I can't think of any clever
> way
> to do this.  I suppose that I could create the PDF, find out the number of
> pages, then have a second pass in which the R script was fed the number of
> pages.  However, there is one disadvantage to this -- the original PDF
> contains a timestamp on each page -- the new version would have a different
> timestamp -- so I would prefer to not use this approach.
>
> Has anyone thought of some terribly clever way to solve this problem?
>
> Dennis
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone / Fax: 1-866-PLessThan (1-866-753-7784)
> www.PLessThan.com
>
> __
> 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] adding "Page X of XX" to PDFs

2023-12-02 Thread CALUM POLWART
Can you provide a very simplified version of how the PDF is created?



On Sat, 2 Dec 2023, 14:39 Dennis Fisher,  wrote:

> OS X
> R 4.3.1
>
> Colleagues
>
> I often create multipage PDFs [pdf()] in which the text "Page X" appears
> in the margin.  These PDFs are created automatically using a massive R
> script.
>
> One of my clients requested that I change this to:
> Page X of XX
> where XX is the total number of pages.
>
> I don't know the number of expected pages so I can't think of any clever
> way to do this.  I suppose that I could create the PDF, find out the number
> of pages, then have a second pass in which the R script was fed the number
> of pages.  However, there is one disadvantage to this -- the original PDF
> contains a timestamp on each page -- the new version would have a different
> timestamp -- so I would prefer to not use this approach.
>
> Has anyone thought of some terribly clever way to solve this problem?
>
> Dennis
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone / Fax: 1-866-PLessThan (1-866-753-7784)
> www.PLessThan.com
>
> __
> 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] ggplot adjust two y-axis

2023-11-25 Thread CALUM POLWART
This is doable. But it's also considered a data visualisation hell! So
Hadley didn't make it easy.

I can provide more details on how to do it later (replying from phone just
now). BUT there is very much a question of should you be plotting like
that. It's probably worth giving it serious thought before figuring out how.


The brief summary of 'how' is to convert the y2 axis values to the y axis
values. Plot it, and add a y2 axis.

So if you were plotting 3 values on y1 with values of 20, 30 and 40. And
the y2 axis should have 150, 350 and 550 for example  then you decide what
150 should be on y1 (is that 20 or perhaps 15??) {This choice changes your
visualisation and hence one of the reasons it can be bad}. If 150 should
appear as 20 you divide all your y2 values by the same proportion (150/20)
and plot them. Then simply add a second y-axis with the scale reversed.





On Sat, 25 Nov 2023, 09:30 ,  wrote:

> Dear Charles-Edouard
>
> Thanks a lot.
> So no way in R to just simply have one ggplot with to axis as in Excel
> (attachment)?
>
> Kind regards
> Sibylle
>
> -Original Message-
> From: Charles-Édouard Giguère 
> Sent: Friday, November 24, 2023 3:14 PM
> To: sibylle.stoec...@gmx.ch; r-help@r-project.org
> Subject: RE: [R] ggplot adjust two y-axis
>
> You could also use more simply facet_wrap(~ Studien_Flaeche).
> Charles-Édouard
>
> -Message d'origine-
> De : Charles-Édouard Giguère  Envoyé : 24 novembre
> 2023 09:11 À : sibylle.stoec...@gmx.ch; r-help@r-project.org Objet : RE:
> [R]
> ggplot adjust two y-axis
>
> Hi Sibylle,
> For that kind of data with two different scales, I generally use two graphs
> that I name gg1 and gg2 and join them using gridExtra::grid.arrange(gg1,
> gg2). This way, the red part of your graph is easier to interpret.
> Have a nice day,
> Charles-Édouard
>
> -Message d'origine-
> De : R-help  De la part de
> sibylle.stoec...@gmx.ch Envoyé : 24 novembre 2023 05:52 À :
> r-help@r-project.org Objet : [R] ggplot adjust two y-axis
>
> Dear R-users
>
> Is it possible to adjust two y-axis in a ggplot differently?
> - First y axis (0-60)
> - Second y axis (0-2500)
>
>
> ### Figure 1
> ggplot(Fig1,aes(BFF,Wert,fill=Studien_Flaeche))+
>   geom_bar(stat="identity",position='dodge')+
>   scale_y_continuous(name="First Axis", sec.axis=sec_axis(trans=~.*50,
> name="Second Axis"))+
>   scale_fill_brewer(palette="Set1")
>
> Thanks a lot
> Sibylle
>
>
> __
> 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] I need to create new variables based on two numeric variables and one dichotomize conditional category variables.

2023-11-05 Thread CALUM POLWART
In this case I think I've made the labels the number and so a double is
possible. But it wasn't what I actually set out to do!  (I'm a tidy fab so
would have to engage the brain in base too much)

When I thought 'I think I might say that's a factor (sometimes in medical
equations gender is shown as a "F" and described as a "factor". Not our
factors... But still a factor).

My programming is never efficient!

But I was planning for a scenario for where gender is not a binary concept,
adding unknowns, trans etc. and if the data set is very large then
obviously storing as factors is less memory intensive, but processing may
be more intensive.








On Sun, 5 Nov 2023, 04:27 ,  wrote:

> There are many techniques Callum and yours is an interesting twist I had
> not considered.
>
> Yes, you can specify what integer a factor uses to represent things but
> not what I meant. Of course your trick does not work for some other forms
> of data like real numbers in double format. There is a cost to converting a
> column to a factor that is recouped best if it speeds things up multiple
> times.
>
> The point I was making was that when you will be using group_by,
> especially if done many times, it might speed things up if the column is
> already a normal factor, perhaps just indexed from 1 onward. My guess is
> that underneath the covers, some programs implicitly do such a factor
> conversion if needed. An example might be aspects of the ggplot program
> where you may get a mysterious order of presentation in the graph unless
> you create a factor with the order you wish to have used and avoid it
> making one invisibly.
>
> From: CALUM POLWART 
> Sent: Saturday, November 4, 2023 7:14 PM
> To: avi.e.gr...@gmail.com
> Cc: Jorgen Harmse ; r-help@r-project.org;
> mkzama...@gmail.com
> Subject: Re: [R] I need to create new variables based on two numeric
> variables and one dichotomize conditional category variables.
>
> I might have factored the gender.
>
> I'm not sure it would in any way be quicker.  But might be to some extent
> easier to develop variations of. And is sort of what factors should be
> doing...
>
> # make dummy data
> gender <- c("Male", "Female", "Male", "Female")
> WC <- c(70,60,75,65)
> TG <- c(0.9, 1.1, 1.2, 1.0)
> myDf <- data.frame( gender, WC, TG )
>
> # label a factor
> myDf$GF <- factor(myDf$gender, labels= c("Male"=65, "Female"=58))
>
> # do the maths
> myDf$LAP <- (myDf$WC - as.numeric(myDf$GF))* myDf$TG
>
> #show results
> head(myDf)
>
> gender WC  TG GF  LAP
> 1   Male 70 0.9 58 61.2
> 2 Female 60 1.1 65 64.9
> 3   Male 75 1.2 58 87.6
> 4 Female 65 1.0 65 64.0
>
>
> (Reality: I'd have probably used case_when in tidy to create a new numeric
> column)
>
>
>
>
> The equation to
> calculate LAP is different for male and females. I am giving both equations
> below.
>
> LAP for male = (WC-65)*TG
> LAP for female = (WC-58)*TG
>
> My question is 'how can I calculate the LAP and create a single new column?
>
> [[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.


Re: [R] I need to create new variables based on two numeric variables and one dichotomize conditional category variables.

2023-11-04 Thread CALUM POLWART
I might have factored the gender.

I'm not sure it would in any way be quicker.  But might be to some extent
easier to develop variations of. And is sort of what factors should be
doing...

# make dummy data
gender <- c("Male", "Female", "Male", "Female")
WC <- c(70,60,75,65)
TG <- c(0.9, 1.1, 1.2, 1.0)
myDf <- data.frame( gender, WC, TG )

# label a factor
myDf$GF <- factor(myDf$gender, labels= c("Male"=65, "Female"=58))

# do the maths
myDf$LAP <- (myDf$WC - as.numeric(myDf$GF))* myDf$TG

#show results
head(myDf)

gender WC  TG GF  LAP
1   Male 70 0.9 58 61.2
2 Female 60 1.1 65 64.9
3   Male 75 1.2 58 87.6
4 Female 65 1.0 65 64.0


(Reality: I'd have probably used case_when in tidy to create a new numeric
column)





The equation to
> calculate LAP is different for male and females. I am giving both equations
> below.
>
> LAP for male = (WC-65)*TG
> LAP for female = (WC-58)*TG
>
> My question is 'how can I calculate the LAP and create a single new column?
>
>

[[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] Question about R software and output

2023-10-03 Thread CALUM POLWART
Charity

There is OFTEN confusion what we mean when we say "R".

R is effectively a single bit of software with a ton of other bits of
software as optional extras.  You might think of some of those optional
extras like apps on a phone. You'd say you have a phone when you can open
the box and power it on. But you might add say "Spotify" app to it. That
will then be downloading the songs. And inevitably sending some data back
(I not do Spotify - no idea what - but it must have your identification and
what songs to play as a minimum).

R packages are like apps. They interact with the R core and do sometimes
amazing things. I think the majority do all that entirely on the machine
running R. BUT some may be using external services. There is for instance a
package that can interact with the Twitter API.  It would be impossible to
do that without sending as a minimum some login data and downloading data
back.  But you'd not normally send your entire research database to Twitter
during the login!

There will be SOME R packages that may be doing some odd stuff which might
need the dataset sent to the web. I can't think of any! Then there are
packages that could accidentally send data that you may or may not consider
sensitive. Say for instance you have a postcode list for every patient in
your research study. And you wanted to geocode that to get their location
as a long/lat... you can do that in an r package - which will have to send
the post code to get the answer. You haven't identified why you want the
postcode... but it is patient identifiable data...

That's R.

Add to that R Studio (or possibly other software solutions) - which is a
development environment which sits on top of R. It's often what people mean
by programming in R but it's effectively a glorified text editor. R Studio
desktop doesn't send data anywhere. Although it has database connectors
that could (but so can excel so if IG are flipping out feel free to remind
them of that!).

R Studio can work with git which is a version management system and can
upload code to a service like GitHub. You COULD upload data in that, or you
could chose not to.

And finally...

R Studio has a cloud version. It looks 98% the same as R Studio desktop.
Now called Posit.Cloud. That's a cloud service. While it may be secure etc
-- you are processing on their server not your PC.  And if this was your
question - it's a whole different set of answers!!


You may also want to Google NHSRcommunity where you might find help if
there are IG question to address as many of us will have wrestled with an
NHS IG team at some point.



On Tue, 3 Oct 2023, 17:26 Michael Dewey,  wrote:

> Dear Charity
>
> Since your organisation is a member of King's Health Partners you might
> like to ask colleagues in KCL for local support.
>
> Michael
>
> On 02/10/2023 08:48, Ferguson Charity (CEMINFERGUSON) wrote:
> > To whom it may concern,
> >
> >
> >
> > My understanding is that the R software is downloaded from a CRAN
> network and data is imported into it using Microsoft Excel for example.
> Could I please just double check whether any data or results from the
> output is held on external servers or is it just held on local files on the
> computer?
> >
> >
> >
> > Many thanks,
> >
> >
> >
> > Charity
> >
> >
> >
> *
> >
> > The information contained in this message and or attachments is intended
> only for the
> > person or entity to which it is addressed and may contain confidential
> and/or
> > privileged material. Unless otherwise specified, the opinions expressed
> herein do not
> > necessarily represent those of Guy's and St Thomas' NHS Foundation Trust
> or
> > any of its subsidiaries. The information contained in this e-mail may be
> subject to
> > public disclosure under the Freedom of Information Act 2000. Unless the
> information
> > is legally exempt from disclosure, the confidentiality of this e-mail
> and any replies
> > cannot be guaranteed.
> >
> > Any review, retransmission,dissemination or other use of, or taking of
> any action in
> > reliance upon, this information by persons or entities other than the
> intended
> > recipient is prohibited. If you received this in error, please contact
> the sender
> > and delete the material from any system and destroy any copies.
> >
> > We make every effort to keep our network free from viruses. However, it
> is your
> > responsibility to ensure that this e-mail and any attachments are free
> of viruses as
> > we can take no responsibility for any computer virus which might be
> transferred by
> > way of this e-mail.
> >
> >
> *
> >
> >   [[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 t

Re: [R] How to fix this problem

2023-09-25 Thread CALUM POLWART
Using readr to read the data might let you clean it on the way in...

readr::read_csv("filename.csv", col_types = list(rep(col_numeric(),6))

On Mon, 25 Sep 2023, 16:54 Ebert,Timothy Aaron,  wrote:

> An update please:
> Collectively we have suggested removing commas from the "E..coli" column,
> checking for different forms of "NA", and looking outside the dataset for
> e-trash (spaces, text, or other content). For removing commas, I would use
> global replace to ensure that all commas were removed from all columns.
>
>
> Did this solve the problem?
>
> If not can you share some early lines and end lines from the data, and how
> R is reading your data? Something simple like head(KD6), tail(KD6), and
> str(KD6).
>
>
>
> -Original Message-
> From: R-help  On Behalf Of Michael Dewey
> Sent: Monday, September 25, 2023 11:09 AM
> To: avi.e.gr...@gmail.com; 'Parkhurst, David' ;
> r-help@r-project.org
> Subject: Re: [R] How to fix this problem
>
> [External Email]
>
> It looks here as though the E coli column has commas in it so will be
> treated as character.
>
> Michael
>
> On 25/09/2023 15:45, avi.e.gr...@gmail.com wrote:
> > David,
> >
> > This may just be the same as your earlier problem. When the type of a
> column is guessed by looking at the early entries, any non-numeric entry
> forces the entire column to be character.
> >
> > Suggestion: fix your original EXCEL FILE or edit your CSV to remove the
> last entries that look just lie commas.
> >
> >
> > -Original Message-
> > From: R-help  On Behalf Of Parkhurst,
> > David
> > Sent: Sunday, September 24, 2023 2:06 PM
> > To: r-help@r-project.org
> > Subject: [R] How to fix this problem
> >
> > I have a matrix, KD6, and I m trying to get a correlation matrix from
> it.  When I enter cor(KD6), I get the message  Error in cor(KD6) : 'x' must
> be numeric .
> > Here are some early lines from KD6:
> >  Flow  E..coliTNSRP TPTSS
> > 1  38.82,4201.65300 0.0270 0.0630  66.80
> > 2 133.02,4201.39400 0.0670 0.1360   6.80
> > 3  86.2   101.73400 0.0700 0.1720  97.30
> > 4   4.85,3900.40400 0.0060 0.0280   8.50
> > 5   0.32,4900.45800 0.0050 0.0430  19.75
> > 6   0.0  1860.51200 0.0040 0.0470  12.00
> > 7  11.19,8351.25500 0.0660 0.1450  12.20
> >
> > Why are these not numeric?
> > There are some NAs later in the matrix, but I get this same error if I
> ask for cor(KD6[1:39,]) to leave out the lines with NAs.  Are they a
> problem anyway?
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat/
> > .ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7Ctebert%40ufl.edu
> > %7Cab9f2511a43e4f0cc0f308dbbdd95e2f%7C0d4da0f84a314d76ace60a62331e1b84
> > %7C0%7C0%7C638312513538190955%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAw
> > MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sda
> > ta=kbguZQ1HLECz6FFh%2FEZI5A1mI3GweE1q7WgUGLxpjOI%3D&reserved=0
> > PLEASE do read the posting guide
> > http://www.r/
> > -project.org%2Fposting-guide.html&data=05%7C01%7Ctebert%40ufl.edu%7Cab
> > 9f2511a43e4f0cc0f308dbbdd95e2f%7C0d4da0f84a314d76ace60a62331e1b84%7C0%
> > 7C0%7C638312513538190955%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiL
> > CJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=By
> > 82TIbEPatOL9qRBoDbZ1tojvTd1%2B2Wo3UaBkIlt70%3D&reserved=0
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
> --
> Michael
>
> __
> 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] OFF TOPIC: chatGPT glibly produces a lot of wrong answers?

2023-08-13 Thread CALUM POLWART
It does often behave better if you say to it "that doesn't seem to be
working" and perhaps some error message

It is afterall a language tool. Its function is to provide text that seems
real.

If you ask it a science question and ask it to provide references in
Vancouver format, it can format the references perfectly. They will be from
real authors (often who have published in the general field), they will be
in real journals for the field. But the title is entirely false but
plausible.

Expect many a scammer to get caught out...

On Sun, 13 Aug 2023, 18:50 Bert Gunter,  wrote:

> **OFF TOPIC** but perhaps of interest to some on this list. I apologize in
> advance to those who may be offended.
>
> The byline:
> 
> "ChatGPT's odds of getting code questions correct are worse than a coin
> flip
>
> But its suggestions are so annoyingly plausible"
> *
> from here:
> https://www.theregister.com/2023/08/07/chatgpt_stack_overflow_ai/
>
> Hmm... Perhaps not surprising. Sounds like some expert consultants I've
> met. 😕
>
> Just for amusement. I am ignorant about this and have no strongly held
> views,
>
> Cheers to all,
> Bert
>
> [[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.


Re: [R] geom_smooth

2023-08-11 Thread CALUM POLWART
+ geom_ribbon(stat = "smooth",
  se = TRUE,
  alpha = 0, # or, use fill = NA
  colour = "black",
  linetype = "dotted")

Does that work?



On Sat, 12 Aug 2023, 06:12 Rui Barradas,  wrote:

> Às 05:17 de 12/08/2023, Thomas Subia via R-help escreveu:
> > Colleagues,
> >
> > Here is my reproducible code for a graph using geom_smooth
> > set.seed(55)
> > scatter_data <- tibble(x_var = runif(100, min = 0, max = 25)
> > ,y_var = log2(x_var) + rnorm(100))
> >
> > library(ggplot2)
> > library(cowplot)
> >
> > ggplot(scatter_data,aes(x=x_var,y=y_var))+
> >geom_point()+
> >geom_smooth(se=TRUE,fill="blue",color="black",linetype="dashed")+
> >theme_cowplot()
> >
> > I'd like to add a black boundary around the shaded area. I suspect this
> can be done with geom_ribbon but I cannot figure this out. Some advice
> would be welcome.
> >
> > Thanks!
> >
> > Thomas Subia
> >
> > __
> > 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.
> Hello,
>
> Here is a solution. You ,ust access the computed variables, which you
> can with ?ggplot_build.
> Then pass them in the data argument.
>
>
>
> p <- ggplot(scatter_data,aes(x=x_var,y=y_var)) +
>geom_point()+
>geom_smooth(se=TRUE,fill="blue",color="black",linetype="dashed")+
>theme_cowplot()
>
> # this is a data.frame, relevant columns are x,  ymin and ymax
> fit <- ggplot_build(p)$data[[2]]
>
> p +
>geom_line(data = fit, aes(x, ymin), linetype = "dashed", linewidth = 1)
> +
>geom_line(data = fit, aes(x, ymax), linetype = "dashed", linewidth = 1)
>
>
> Hope this helps,
>
> Rui Barradas
>
> __
> 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] Live data collection, analysis & update of slides ..

2023-07-22 Thread CALUM POLWART
I'm looking for a way to do some live data analysis taking audience votes,
presenting their results, potentially posing some new questions to vote on,
and present those and vote.

I'm interested in any suggestions from the collective minds here about the
potential best approaches.

I can obviously provide a range of presentations (PowerPoint, html etc)
which could pose the initial questions.

I can use a third party audience feedback thing (poll everywhere etc) to
give a likert scale.

Most of those offer a histogram of results. But I want a couple of more
specifics - median (I can probably guess that from the histogram) and IQR
(not aware any of them offer that).  Obviously both would be EASY in R.

Anyone used an audience feedback service with an R accessible API?

Or I can use a survey tool to get the results but they don't pose questions
in time to the on-screen presenter...

>From that data I can have a pre-built quarto to present the results.

I'd also like to have a free text box to let people suggest alternative
versions of what they are voting on. Not come across anything in audience
feedback sessions... Anyone?

Then I want to be able to rerun the votes on the alternatives...

Does anyone have any thoughts on bits of R packages that might join this
all together and pull it off?

The alternative would be a shiny app but thG feels extreme for one
session...

[[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] plotly question

2023-07-22 Thread CALUM POLWART
I was just replying to say which bit do you consider the indicator.

But I see Boris has provided a Chat GPT solution.

Running it hopefully shows you how to change colours on various parts.



On Fri, 21 Jul 2023, 22:43 Jeff Newmiller,  wrote:

> plotly is _not_ associated with posit. I think you are unlikely to find
> expertise with plotly in their forums. You might find help at
> stackoverflow.com.
>
> On July 21, 2023 1:40:49 PM PDT, Bert Gunter 
> wrote:
> >As you apparently haven't received any responses yet, I'll try to
> >suggest something useful. However, I have absolutely zero experience
> >with plotly, so this is just from general principles and reading the
> >plot_ly Help file, which says for the "..." arguments:
> >
> >"Arguments (i.e., attributes) passed along to the trace type. See
> >schema() for a list of acceptable attributes for a given trace type
> >(by going to traces -> type -> attributes). Note that attributes
> >provided at this level may override other arguments (e.g. plot_ly(x =
> >1:10, y = 1:10, color = I("red"), marker = list(color = "blue")))."
> >
> >So I would **guess** that you needs to go to ?schema to see if the
> >further attributes of your "gauge" type that you wish to change are
> >there.
> >
> >Alternatively, plotly is a package from posit.co, formerly RStudio;
> >they have an extensive support site and community here:
> >https://posit.co/support/
> >So you may have success there.
> >
> >Finally, I assume you have tried web searching appropriate search
> >queries, but if not, you should do so. It is sometimes surprising how
> >much you can find that way.
> >
> >... and, again, apologies if my ignorance means my suggestions are
> useless.
> >
> >Cheers,
> >Bert
> >
> >
> >On Fri, Jul 21, 2023 at 6:19 AM Thomas Subia via R-help
> > wrote:
> >>
> >> Colleagues
> >>
> >> Here is my reproducible code
> >>
> >> plot_ly(
> >>   domain = list(x = c(0, 1), y = c(0, 1)),
> >>   value = 2874,
> >>   title = list(text = "Generic"),
> >>   type = "indicator",
> >>   mode = "gauge+number+delta",
> >>   delta = list(reference = 4800),
> >>   gauge = list(
> >> axis =list(range = list(NULL, 5000)),
> >> steps = list(
> >> list(range = c(0, 4800), color = "white"),
> >> list(range = c(4800, 6000), color = "red")),
> >> threshold = list(
> >> line = list(color = "black", width = 6),
> >> thickness = 0.75,
> >> value = 4800)))
> >>
> >> How can I change the indicator color from green to some other color?
> >>
> >> How can I change the typeface and font size of the speedometer tick
> mark font size?
> >>
> >> Thomas Subia
> >>
> >> [[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.
>
> --
> 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.


Re: [R] how to change the y-axis to logarithmic in a barplot ggplot

2023-07-16 Thread CALUM POLWART
The data snippet doesn't make sense for the code you provided

Using the snippet I'd be doing

ggplot2(fc,  aes(x = ID, y= value)) +
geom_col() +
scale_y_log10()

And adjusting...

Not sure if that's what you are trying to do?


On Sun, 16 Jul 2023, 23:57 Maria Lathouri,  wrote:

> I will find the ggplot help.
>
> But I have tried everything, including what you have suggested and nothing
> works.
>
> Kind regards,
> Maria
>
>
>
>
>
>
> Στις Κυριακή 16 Ιουλίου 2023 στις 11:22:36 μ.μ. GMT+1, ο χρήστης CALUM
> POLWART  έγραψε:
>
>
>
>
>
> Try adding
>
> scale_y_log10()
>
> This is a general R help list. It's not a ggplot list and you are likely
> to be chased off to ggplot's package maintainers nominated support pages.
>
> But really a Google search should surely have found this?
>
>
>
> On Sun, 16 Jul 2023, 22:51 Maria Lathouri via R-help, <
> r-help@r-project.org> wrote:
> > Dear all,
> >
> > ggplot(fc, aes(x = Temp, y = mean, fill = Glass)) +
> > geom_bar(stat = "identity", position = "dodge", aes(y=log(mean)))
> > + theme_bw() + theme(panel.grid.major = element_blank(),
> panel.grid.minor = element_blank()) + theme(legend.position = c(0.45,
> 0.85), legend.title = element_blank())
> > + scale_fill_brewer(palette = "Dark2") + scale_color_brewer(palette =
> "Dark2") +
> >
> scale_y_log10()
>
>

[[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] how to change the y-axis to logarithmic in a barplot ggplot

2023-07-16 Thread CALUM POLWART
Try adding

scale_y_log10()

This is a general R help list. It's not a ggplot list and you are likely to
be chased off to ggplot's package maintainers nominated support pages.

But really a Google search should surely have found this?



On Sun, 16 Jul 2023, 22:51 Maria Lathouri via R-help, 
wrote:

> Dear all,
>
> ggplot(fc, aes(x = Temp, y = mean, fill = Glass)) +
> geom_bar(stat = "identity", position = "dodge", aes(y=log(mean)))
> + theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor
> = element_blank()) + theme(legend.position = c(0.45, 0.85), legend.title =
> element_blank())
> + scale_fill_brewer(palette = "Dark2") + scale_color_brewer(palette =
> "Dark2") +
>
scale_y_log10()

[[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] Asking about R "Security" ..

2023-05-17 Thread CALUM POLWART
Chris replied off list to say he hadn't directed the OP to NHS R Community
so it seems prudent to point a link here for eternity -- because there will
be another NHS Security Audit with questions that don't fit R properly and
the guys in the community may be best placed to answer them

Linky:
https://nhsrcommunity.com/


On Wed, 17 May 2023, 10:49 Chris Evans via R-help, 
wrote:

> Fortune nomination (if trimmed a little) ... thanks to Martin, Ivan and
> so many others who never cease to teach me things here!
>
> (As an ex-NHS person who has used R for countless centuries, slowly less
> awfully courtesy of this list and other angeles, I contacted Ms Majid
> off list to see if I can help!)
>
> Chris
>
> On 17/05/2023 11:11, Martin Maechler wrote:
> >> Ivan Krylov
> >>  on Wed, 17 May 2023 11:52:27 +0300 writes:
> >  > В Tue, 16 May 2023 13:47:19 +
> >  > "MAJID, Ayesha \(NHS ENGLAND - X26\) via R-help"<
> r-help@r-project.org>
> >
> > [ . ]
> > [ . ]
> > [ .. helpful & useful answers / pointers to public information .. ]
> > [ . ]
> > [ . ]
> >
> >  > (Did you mean to ask these questions at the public mailing list
> open
> >  > for J. Random Hackers like me to answer?)
> >
> >  > --
> >  > Best regards,
> >  > Ivan
> >
> > Actually, people typically ask "the R Foundation" or even
> > individual RF / R-core members such as me about this ...
> >
> > ... as if we were a company with staff to answer such questions;
> > but we (volunteering individuals) really do *not* have the time
> > resources for that,
> > and consequently, also in my function---shared with another few
> > individuals---as gatekeeper to the R foundation / R core / R webmaster
> > e-mail addresses, I typically deflect such questions to the
> > public web sites *and* public e-mail lists.
> >
> > The big advantage of this approach is that at least the answers
> > are findable by web searches in the future, and so, hopefully
> > have to be answered less frequently by volunteers as you, Ivan,
> > for whom we are really very grateful.
> >
> > Martin
> >
> > __
> > 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 guidehttp://
> www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> --
> Chris Evans (he/him)
> Visiting Professor, UDLA, Quito, Ecuador & Honorary Professor,
> University of Roehampton, London, UK.
> Work web site: https://www.psyctc.org/psyctc/
> CORE site: http://www.coresystemtrust.org.uk/
> Personal site: https://www.psyctc.org/pelerinage2016/
> 
> 
> [[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.


Re: [R] Asking about R "Security" ..

2023-05-17 Thread CALUM POLWART
Chris

Presumably you've also pointed her to the NHS R community and in particular
is slack group?

There are so many variables in what was even being asked it's going to take
some time to work through, did the mean R or R Studio or R Studio Cloud...
Before any packages..

On Wed, 17 May 2023, 10:49 Chris Evans via R-help, 
wrote:

> Fortune nomination (if trimmed a little) ... thanks to Martin, Ivan and
> so many others who never cease to teach me things here!
>
> (As an ex-NHS person who has used R for countless centuries, slowly less
> awfully courtesy of this list and other angeles, I contacted Ms Majid
> off list to see if I can help!)
>
> Chris
>
> On 17/05/2023 11:11, Martin Maechler wrote:
> >> Ivan Krylov
> >>  on Wed, 17 May 2023 11:52:27 +0300 writes:
> >  > В Tue, 16 May 2023 13:47:19 +
> >  > "MAJID, Ayesha \(NHS ENGLAND - X26\) via R-help"<
> r-help@r-project.org>
> >
> > [ . ]
> > [ . ]
> > [ .. helpful & useful answers / pointers to public information .. ]
> > [ . ]
> > [ . ]
> >
> >  > (Did you mean to ask these questions at the public mailing list
> open
> >  > for J. Random Hackers like me to answer?)
> >
> >  > --
> >  > Best regards,
> >  > Ivan
> >
> > Actually, people typically ask "the R Foundation" or even
> > individual RF / R-core members such as me about this ...
> >
> > ... as if we were a company with staff to answer such questions;
> > but we (volunteering individuals) really do *not* have the time
> > resources for that,
> > and consequently, also in my function---shared with another few
> > individuals---as gatekeeper to the R foundation / R core / R webmaster
> > e-mail addresses, I typically deflect such questions to the
> > public web sites *and* public e-mail lists.
> >
> > The big advantage of this approach is that at least the answers
> > are findable by web searches in the future, and so, hopefully
> > have to be answered less frequently by volunteers as you, Ivan,
> > for whom we are really very grateful.
> >
> > Martin
> >
> > __
> > 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 guidehttp://
> www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> --
> Chris Evans (he/him)
> Visiting Professor, UDLA, Quito, Ecuador & Honorary Professor,
> University of Roehampton, London, UK.
> Work web site: https://www.psyctc.org/psyctc/
> CORE site: http://www.coresystemtrust.org.uk/
> Personal site: https://www.psyctc.org/pelerinage2016/
> 
> 
> [[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.


Re: [R] R does not run under latest RStudio

2023-04-07 Thread CALUM POLWART
Obviously running R is pretty fundamental to running R studio. So it seems
rather odd to be thinking you'd need to stop using R studio unless you are
doing something odd

On Fri, 7 Apr 2023, 02:18 Sorkin, John,  wrote:

> I have also had difficulty running R in RStudio. Has anyone else had
> problems?
>  It will be a shame if we need to abandon R Studio. It is a very good IDE.
> John
>
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior
> to faxing)
>
> On Apr 6, 2023, at 5:30 PM, David Winsemius 
> wrote:
>
> 
> On 4/6/23 03:49, Steven Yen wrote:
> The RStudio list generally does not respond to free version users. I was
> hoping someone one this (R) list would be kind enough to help me.
>
>
> I don't think that is true. It is perhaps true that you cannot get
> personalized help from employed staff, but you can certainly submit to the
> Q&A forum.
>
>
> --
>
> David
>
>
> Steven from iPhone
>
> On Apr 6, 2023, at 6:22 PM, Uwe Ligges 
> wrote:
>
> No, but you need to ask on an RStudio mailing list.
> This one is about R.
>
> Best,
> Uwe Ligges
>
>
>
>
> On 06.04.2023 11:28, Steven T. Yen wrote:
> I updated to latest RStudio (RStudio-2023.03.0-386.exe) but
> R would not run. Error message:
> Error Starting R
> The R session failed to start.
> RSTUDIO VERSION
> RStudio 2023.03.0+386 "Cherry Blossom " (3c53477a, 2023-03-09) for Windows
> [No error available]
> I also tried RStudio 2022.12.0+353 --- same problem.
> I then tried another older version of RStudio (not sure version
> as I changed file name by accident) and R ran.
> Any clues? Please help. Thanks.
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7CJSorkin%40som.umaryland.edu%7C93ce6a082163463da71b08db36e62f3c%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638164134503963420%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=EpNjOFynmxiXP3%2FkBx73iTmJJSX2cBXl92waOopal0A%3D&reserved=0
> PLEASE do read the posting guide
> https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=05%7C01%7CJSorkin%40som.umaryland.edu%7C93ce6a082163463da71b08db36e62f3c%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638164134503963420%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=iOZi2L%2F6B9B3RawVWM5dZ8iJV3SeAJ1K8j5cq38m%2BAA%3D&reserved=0
> 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://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7CJSorkin%40som.umaryland.edu%7C93ce6a082163463da71b08db36e62f3c%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638164134503963420%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=EpNjOFynmxiXP3%2FkBx73iTmJJSX2cBXl92waOopal0A%3D&reserved=0
> PLEASE do read the posting guide
> https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=05%7C01%7CJSorkin%40som.umaryland.edu%7C93ce6a082163463da71b08db36e62f3c%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638164134503963420%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=iOZi2L%2F6B9B3RawVWM5dZ8iJV3SeAJ1K8j5cq38m%2BAA%3D&reserved=0
> and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7CJSorkin%40som.umaryland.edu%7C93ce6a082163463da71b08db36e62f3c%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638164134503963420%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=EpNjOFynmxiXP3%2FkBx73iTmJJSX2cBXl92waOopal0A%3D&reserved=0
> PLEASE do read the posting guide
> https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=05%7C01%7CJSorkin%40som.umaryland.edu%7C93ce6a082163463da71b08db36e62f3c%7C717009a620de461a88940312a395cac9%7C0%7C0%7C638164134503963420%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJ

Re: [R] R does not run under latest RStudio

2023-04-07 Thread CALUM POLWART
R studio sometimes isn't happy with i386 versions. Although I thought they
had put support back in. If you have the option for 64bit, use 64bit R.

I've also had similar issues when R couldn't find the executable.

But absolutely would expect if you post this on the community forum someone
would be along to help.

Screenshots with setup etc will be helpful, which isn't visible on here...

On Thu, 6 Apr 2023, 22:31 David Winsemius,  wrote:

>
> On 4/6/23 03:49, Steven Yen wrote:
> > The RStudio list generally does not respond to free version users. I was
> hoping someone one this (R) list would be kind enough to help me.
>
>
> I don't think that is true. It is perhaps true that you cannot get
> personalized help from employed staff, but you can certainly submit to
> the Q&A forum.
>
>
> --
>
> David
>
> >
> > Steven from iPhone
> >
> >> On Apr 6, 2023, at 6:22 PM, Uwe Ligges 
> wrote:
> >>
> >> No, but you need to ask on an RStudio mailing list.
> >> This one is about R.
> >>
> >> Best,
> >> Uwe Ligges
> >>
> >>
> >>
> >>
> >>> On 06.04.2023 11:28, Steven T. Yen wrote:
> >>> I updated to latest RStudio (RStudio-2023.03.0-386.exe) but
> >>> R would not run. Error message:
> >>> Error Starting R
> >>> The R session failed to start.
> >>> RSTUDIO VERSION
> >>> RStudio 2023.03.0+386 "Cherry Blossom " (3c53477a, 2023-03-09) for
> Windows
> >>> [No error available]
> >>> I also tried RStudio 2022.12.0+353 --- same problem.
> >>> I then tried another older version of RStudio (not sure version
> >>> as I changed file name by accident) and R ran.
> >>> Any clues? Please help. Thanks.
> >>> __
> >>> 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-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] connect MSSQL server problem

2023-03-17 Thread CALUM POLWART
This doesn't sound like it is R failing, it sounds like you don't know the
appropriate connection details for the server. You need to find them out
and come back rather than simply try different username and passwords...

Can you connect to the server using any other ODBC connection and those
credentials?

On Fri, 17 Mar 2023, 19:09 Kai Yang via R-help, 
wrote:

> Hi Team,I need to connect two MSSQL servers. One server ask me to enter
> user name and password. I can use dbConnect (from DBI package) to connect
> the serve.Another one do not ask me credential to access the serve. But
> when I remove UID and PWD, it doesn't work. Then I tried to use my PC log
> in credential for UID and PWD, it still doesn't allow me to access. The
> error message: Error: nanodbc/nanodbc.cpp:1021: 28000: [Microsoft][ODBC
> Driver 17 for SQL Server][SQL Server]Login failed for user '**'. How to
> modify the code (see below) to access second MSSQL server?
> con <- dbConnect(odbc(), Driver   = "ODBC Driver 17 for
> SQL Server", Server   = "abcdefghijklmn",
>  Database = "abc_def")
> Thank you,Kai
> [[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.


Re: [R] Date order question

2023-01-04 Thread CALUM POLWART
On Wed, 4 Jan 2023, 21:29 Ebert,Timothy Aaron,  wrote:

>
> As you are plotting strings, you could put a space character in front of
> the December dates so that they are first.
> date<-c(" 12-29"," 12-30","01-01")
> That fixes the problem in this example. You can order all the dates by
> putting more spaces in front of earlier years. That will get messy.
>

Put the year in front +/- apply as.Date() and you would be fine...

date<-c("2022-12-29","2022-12-30","2023-01-01") |> as.Date()

It may be that the source data doesn't have a year and the example given is
to show us dummy data.  You could 'automate' the addition along the lines
of:

require(tidyverse)
#if you have up to date Tidyverse this includes lubridate
current_date <- sys.Date()
current_month <- month(current_date)
current_year <- year(current_date)
date<-c("12-29","12-30","01-01")
PT <- c(.106,.130,.121)
data <- data.frame(date,PT)
data |>
  # separate the date into month and day column
  separate (date, c("Month", "Day"), sep="-") |>
  # add a year if month is > current month must be last year
 mutate (year = if_else(Month > current_month, current_year - 1,
current_year)) |>
  #rebuild the date
  unite (date, c("Year", "Month", "Day"), sep="-") |>
  mutate(date = as.Date(date)) -> data

If you don't want year on the axis of the graph, that should be dealt with
in ggplot not in the data carpentry

[[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] is it possible to run multiple rmd files together

2023-01-04 Thread CALUM POLWART
I get frustrated by our peers who reply "please provide a worked example"
but OMG... Please provide a worked example!

You can't use:

source("filename.Rmd") as it isn't a simple set of R code.

You can do:

Rmarkdown::render("filename.Rmd")

You can also knit child files. But it is completely unclear what you have
tried, what you want to happen or what your expected outcome is.

On Wed, 4 Jan 2023, 16:19 Kai Yang via R-help,  wrote:

> Hi Team,I have multiple rmd files (~50) for difference study report. I did
> try the source command to run them together, but it seems doesn't work.Is
> there a way to run those rmd files from one script?Thanks,Kai
> [[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.


Re: [R] Reg: To change the x axis label in ts.plot function

2022-12-24 Thread CALUM POLWART
https://stackoverflow.com/questions/49679699/time-series-plot-change-x-axis-format-in-r

Is as good a solution as possible using ts I think.

On Sat, 24 Dec 2022, 18:58 Upananda Pani,  wrote:

>   Dear All,
>  I have the data set with daily dates (5-days trading in a week) and price
> data. I want to change the x axis labels to the plot. I am using ts.plot
> function to plot my data. My data spans from 2020-01-27 to 2021-07-30. I
> want to change it to D-M-Y first. Then I want to show all the dates with a
> one week gap in my x-axis label.
>
>  The following code I am using:
>  pricet <- ts(price, start = c(2020, 27), frequency = 260)
> plot.ts(pricet)
>
> Please advise me how to achieve the desired result. I have attached my data
> and the plot which I am currently getting with ts.plot.
>
> With sincere regards,
> Upananda Pani
> __
> 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] datatable using dt not able to print background colors

2022-12-17 Thread CALUM POLWART
I don't think this is an R issue, it's a HTML tables issue // browser issue.

There are some hacks using background image (not R specific).

BUT before you do any of this... Consider if colour is your answer!  8% of
males are colour blind, so your table isn't as accessible as you may think
it is. That's before you get to people who print in B&W etc

On Sat, 17 Dec 2022, 00:21 Matthew Pirritano,  wrote:

> Hey, all!
>
> I've got a report that uses datatable from DT to create an rmarkdown html
> that looks great as an html but when I try to print it, to a printer, or to
> a pdf the colors I've assigned to cells are not displaying. I'm using
> chrome and I've clicked on the Background graphics button there, but that
> doesn't help print the colors. I have tried to run the datatable section of
> the code using results = 'asis' and eliminating results = 'asis'. Neither
> seems to help with the
>
> My css style at the top of the rmarkdown is
>
> 
> .main-container {
>   max-width: 1500px;
>   margin-left: auto;
>   margin-right: auto;
>   table.display td { white-space: wrap; }
>
> }
> td{
>   -webkit-print-color-adjust:exact !important;
>   print-color-adjust:exact !important;
> }
> 
>
> I added the webkit bit based on what I've found online. Maybe I have
> something set up incorrectly there? Any ideas or thoughts on how to get
> this to print the background colors?
>
> Thanks
> matt
>
>
>
>
> 
>
> This communication is intended for the use of the individual or entity to
> which it is addressed and may contain information that is privileged,
> confidential or otherwise exempt from disclosure under applicable law. If
> you are not the intended recipient, you are hereby notified that any
> dissemination, distribution or copying of this communication is strictly
> prohibited. If you have received this communication in error, please notify
> the sender and delete any copies. Thank you.
>
> [[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.


Re: [R] getting data from a "vertical" table into a "2-dimensional" grid

2022-10-21 Thread CALUM POLWART
You asked for base R but also said or using other methods. So for
completeness here is a solution using Tidyverse

library(tidyverse)
data_original <- data.frame(
  year = c('1990', '1999', '1990', '1989'),
  size = c('s', 'l', 'xl', 'xs'),  n = c(99, 33, 3, 4) )

data_original |>
  pivot_wider(
id_cols = year,
names_from = size,
values_from = n
  )

# A tibble: 3 x 5
  year  s lxlxs
  
1 1990 99NA 3NA
2 1999 NA33NANA
3 1989 NANANA 4


If you really  want a matrix add

 |>
as.matrix()

To the end.

I saw you asked if you can use column position and the answer is the same
here you can replace size with 2. BUT beware this is prone to errors if
data gets changes in order etc.

This obviously needs to use tidyverse which some people hate. But it does
make the code much more readable to understand what you are doing...

On Fri, 21 Oct 2022, 23:34 Kelly Thompson,  wrote:

> As my end result, I want a matrix or data frame, with one row for each
> year, and one column for each category.
>
> On Fri, Oct 21, 2022 at 6:23 PM Kelly Thompson 
> wrote:
> >
> > # I think this might be a better example.
> >
> > # I have data presented in a "vertical" dataframe as shown below in
> > data_original.
> > # I want this data in a matrix or "grid", as shown below.
> > # What I show below seems like one way this can be done.
> >
> > # My question: Are there easier or better ways to do this, especially
> > in Base R, and also in R packages?
> >
> > #create data
> > set.seed(1)
> > data_original <- data.frame(year = rep(1990:1999, length  = 50),
> > category = sample(1:5, size = 50, replace = TRUE),  sales =
> > sample(0:9, size = 50 , replace = TRUE) )
> > dim(data_original)
> >
> > #remove rows where data_original$year == 1990 & data_original$category
> > == 5, to ensure there is at least one NA in the "grid"
> > data_original <- data_original[ (data_original$year == 1990 &
> > data_original$category == 5) == FALSE, ]
> > dim(data_original)
> >
> > #aggregate data
> > data_aggregate_sum_by_year_and_category <- aggregate(x =
> > data_original$sales, by = list(year = data_original$year, category =
> > data_original$category), FUN = sum)
> > colnames(data_aggregate_sum_by_year_and_category) <- c('year',
> > 'category', 'sum_of_sales')
> > dim(data_aggregate_sum_by_year_and_category)
> >
> > data_expanded <- expand.grid(year =
> > unique(data_aggregate_sum_by_year_and_category$year), category =
> > unique(data_aggregate_sum_by_year_and_category$category))
> > dim(data_expanded)
> > data_expanded <- merge(data_expanded,
> > data_aggregate_sum_by_year_and_category, all = TRUE)
> > dim(data_expanded)
> >
> > mat <- matrix(data = data_expanded$sum_of_sales, nrow =
> > length(unique(data_expanded$year)), ncol =
> > length(unique(data_expanded$category)) , byrow = TRUE, dimnames =
> > list( unique(data_expanded$year), unique(data_expanded$category) ) )
> >
> >
> > data_original
> > data_expanded
> > mat
> >
> > On Fri, Oct 21, 2022 at 5:03 PM Kelly Thompson 
> wrote:
> > >
> > > ###
> > > #I have data presented in a "vertical" data frame as shown below in
> > > data_original.
> > > #I want this data in a matrix or "grid", as shown below.
> > > #What I show below seems like one way this can be done.
> > >
> > > #My question: Are there easier or better ways to do this, especially
> > > in Base R, and also in R packages?
> > >
> > > #reproducible example
> > >
> > > data_original <- data.frame(year = c('1990', '1999', '1990', '1989'),
> > > size = c('s', 'l', 'xl', 'xs'),  n = c(99, 33, 3, 4) )
> > >
> > > data_expanded <- expand.grid(unique(data_original$year),
> > > unique(data_original$size), stringsAsFactors = FALSE )
> > > colnames(data_expanded) <- c('year', 'size')
> > > data_expanded <- merge(data_expanded, data_original, all = TRUE)
> > >
> > > mat <- matrix(data = data_expanded $n, nrow =
> > > length(unique(data_expanded $year)), ncol =
> > > length(unique(data_expanded $size)) , byrow = TRUE, dimnames = list(
> > > unique(data_expanded$year), unique(data_expanded$size) ) )
> > >
> > > data_original
> > > data_expanded
> > > mat
>
> __
> 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] removing non-table lines

2022-09-18 Thread CALUM POLWART
Can you provide a sample of say the first 3 rows then the last 2 rows
before the CSV starts.

Are there always the same number of lines at the top? Or can it vary
depending what non-sense the Met Office decided to contaminate it with?

This should be solvable with some sample data.

Base R or Tidyverse? Any limitations on packages (e.g. stringr?)

On Sun, 18 Sep 2022, 20:40 Nick Wray,  wrote:

> Hello - I am having to download lots of rainfall and temperature data in
> csv form from the UK Met Office.  The data isn't a problem - it's in nice
> columns and can be read into R easily - the problem is that in each csv
> there are 60 or so lines of information first which are not part of the
> columnar data.  If I read the whole csv into R the column data is now
> longer in columns but in some disorganised form - if I manually delete all
> the text lines above and download I get a nice neat data table.  As the
> text lines can't be identified in R by line numbers etc I can't find a way
> of deleting them in R and atm have to do it by hand which is slow.  It
> might be possible to write a complicated and dirty algorithm to rearrange
> the meteorological data back into columns but I suspect that it might be
> hard to get right and consistent across every csv sheet and any errors
> might be hard to spot.   I can't find anything on the net about this - has
> anyone else had to deal with this problem and if so do they have any
> solutions using R?
> Thanks Nick Wray
>
> [[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.


Re: [R] Remove line from data file

2022-09-18 Thread CALUM POLWART
If you want to delete row 18 you can do

mydf <- mydf[-18,]

This selects all rows other than row 18, and all columns and 'saves' it
back to the original data frame. Many people prefer to allocate to a new
dataframe so that if the -18 is wrong they can simply fix things.

I wasn't sure if you knew the row you wanted to delete. If you had a frame
with names and ages in. David Parkhurst might be row 18 and you might want
to delete him. But if the data is ever updated, he may move row.  If you
always want to delete David, it would be better to do:

mydf2 <- mydf[name != "David Parkhurst", ]




On Sun, 18 Sep 2022, 13:48 Parkhurst, David,  wrote:

> Thank you for your reply.  I meant from the dataframe, but that’s one of
> the terms I had forgotten.  I created that from read.csv, the csv file
> coming from Excel.  Last night I went ahead and made the change(s) using
> Excel.
>
>
>
> For future reference, when I look at your solutions below, what do you
> mean by “value to delete”?  Could that just be a row number?  I was wanting
> to delete something like the 18th row in the dataframe?
>
>
>
> *From: *CALUM POLWART 
> *Date: *Sunday, September 18, 2022 at 7:25 AM
> *To: *Parkhurst, David 
> *Cc: *R-help@r-project.org 
> *Subject: *Re: [R] Remove line from data file
>
> From the file? Or the data frame once its loaded?
>
>
>
> What format is the file? CSV?
>
>
>
> Do you know the line that needs deleted?
>
>
>
> mydf <- read.csv("myfile.csv")
>
>
>
> mydf2 <- mydf[-columnName == "valuetodelete", ]
>
> # Note the - infront of column name
>
> # or perhaps columnName != "value to delete", ]
>
>
>
> write.csv(mydf2, "mydeletedfile.csv")
>
>
>
>
>
>
>
>
>
> On Sun, 18 Sep 2022, 10:33 Parkhurst, David,  wrote:
>
> I’ve been retired since ‘06 and have forgotten most of R.  Now I have a
> use for it.  I’ve created a data file and need to delete one row from it.
> How do I do that?
>
> DFP (iPad)
> __
> 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] Remove line from data file

2022-09-18 Thread CALUM POLWART
>From the file? Or the data frame once its loaded?

What format is the file? CSV?

Do you know the line that needs deleted?

mydf <- read.csv("myfile.csv")

mydf2 <- mydf[-columnName == "valuetodelete", ]
# Note the - infront of column name
# or perhaps columnName != "value to delete", ]

write.csv(mydf2, "mydeletedfile.csv")




On Sun, 18 Sep 2022, 10:33 Parkhurst, David,  wrote:

> I’ve been retired since ‘06 and have forgotten most of R.  Now I have a
> use for it.  I’ve created a data file and need to delete one row from it.
> How do I do that?
>
> DFP (iPad)
> __
> 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] Need to insert various rows of data from a data frame after particular rows from another dataframe

2022-07-26 Thread CALUM POLWART
Not very clear what you are trying to do. But I'd have thought possibly
dplyr left_join might be a solution for you.  The base R equivalent is
merge().

It might be a rbind or cbind can do it too.

On Wed, 27 Jul 2022, 03:30 Ranjeet Kumar Jha, 
wrote:

> Hello Everyone,
>
> I have dataset in a particular format in "dacnet_yield_update till
> 2019.xlsx" file, where I need to insert the data of rows 2018-2019 and
> 2019-2020 for the districts those data are available in "Kharif crops
> yield_18-19.xlsx".  I need to insert these two rows of data belonging to
> every district, if data is available in a later excel file, just after the
> particular crop group data for the particular district.
>
> I have put the data file in the given link.
>
> https://drive.google.com/drive/u/0/folders/1dNmGTI8_c9PK1QqmfIjnpbyzuiCXgxFC
>
> Please help solving this problem.
>
> Regards and Thanks,
> Ranjeet
>
> [[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.


Re: [R] Restoration of "rite" package of R as R-script editor or the like

2022-05-23 Thread CALUM POLWART
As has been said, it's not for R CRAN to fix. This is open source code. If
the package maintainer is no longer keen anyone can fork the code, maintain
it and release it back to Cran and provided it meets their rules it would
be available for all. (If it doesn't you just need to provide the install
instructions from a different source.) This ability is the beauty of
open source.

However, I'm not sure what "rite" really adds. It's a bit better than base
R and not as good as R Studio. So why not just use R Studio. What is too
much for them? The description for rite, reads pretty much how I tell
people to use R Studio.

On Sun, 22 May 2022, 07:33 Jeff Newmiller,  wrote:

> As respectful as you are trying to be, this isn't normally how open source
> happens. Open source is a herd of cats, and the more "in charge" some of
> those cats are, the less interested they tend to become in scratching
> _your_ itch... they respect doers, not askers.
>
> Open source is developed and maintained by people like you... who need a
> feature. Such people rarely start out knowing how to do this... it is much
> more common that they have to learn as they go. But people who did not have
> that need rarely stick around to maintain a project even if they help out
> for awhile... so _you_ are likely going to need to do or at the very least
> help do this since it is so urgent for you.
>
> Note that occasionally a corporate sponsor will donate some money to pay
> students for awhile... like Google Summer of Code. But the maintenance is
> still tough afterward... sometimes it takes off, other times not.
>
> FWIW there are way too many independently maintained editors and terminal
> programs already out there for this to resonate with me. I don't share your
> interest in such a "minimalist" extension in the slightest... but I am just
> one mailing-list member.
>
> On May 20, 2022 6:19:43 AM PDT, Akhilesh Singh <
> akhileshsingh.i...@gmail.com> wrote:
> >Dear Sir,
> >
> >I am a professor at Indira Gandhi Agricultural University, Raipur,
> >Chhattisgarh, India. I have been teaching statistics in my department
> since
> >1986.
> >
> >Almost since the last 10 years, I have included R capabilities in doing
> >practical-classes of various statistics courses in my department. I use
> the
> >default R-script editor that comes with RGUI.exe for that purpose. *But,
> >this text editor is too simple without syntax highlighting etc. And
> RStudio
> >is too heavy for the UG/PG level students who are basically from
> >agriculture stream.*
> >
> >Meanwhile, I came across a "rite" package which was earlier maintained
> >by Thomas
> >J. Leeper . Now, it has been put into archives and
> >not being maintained by anyone.
> >
> >At present, I am using the "rite" package for students' practical classes.
> >But, I am facing difficulties using it. Sometimes, it hangs unnecessarily,
> >and some of its features do not work, probably because it is not being
> >maintained anymore by CRAN.
> >
> >Therefore, to remove this difficulty, the "rite" package must be
> maintained.
> >
> >
> >Sir, "rite" package is a very light weight editor for R codes suitable for
> >teaching to beginner students, with syntax highlighting facility and with
> >the facility of generating reports into HTML, markdown etc.
> >
> >Therefore, I request you ,*one and all who are in control, to kindly make
> >sure to include the "rite" package into the regular packages with proper
> >maintenance, which will immensely help the beginner students to learn R*.
> >
> >Or,
> >
> >Kindly make sure that the *default R-script-editor gets the syntax
> >highlighting features and capability of creating basic reports*.
> >
> >Or,
> >
> >Kindly make a lighter version of RStudio *for beginner student-level only,
> >like the "rite" package,*  for executing R-scripts and for generating some
> >basic reports.
> >
> >*In fact, the lack of a proper R-script editor is a major handicap among
> >the beginner students to learn R.*
> >
> >Therefore, I earnestly request your kind attention to this problem.
> >
> >Thaing you.
> >
> >
> >Dr. A.K. Singh
> >Professor and Ex-Head (Agricultural Statistics)
> >Department of Agricultural Statistics and Social Science (L)
> >Indira Gandhi Krishi Vishwavidyalaya, Raipur-492 012,
> >Chhattisgarh, India
> >Mobile: +918770625795
> >Email: akhileshsingh.i...@gmail.com
> >
> >   [[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.
>
> --
> 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 

Re: [R] Not sure this is something R could do but it feels like it should be.

2013-06-09 Thread Calum Polwart

Calum


Hi Calum,
I can only answer from the perspective of someone who calculated
doses of alcohol for experimental subjects many years ago. It was not
possible to apply a linear function across the range due to a number
of factors. One is that BAC, which was the target value, is dependent
upon the proportion of the weight that represents the water
compartment of the body. This varies with both weight (heavier people
typically have a higher proportion of fat) and sex (women also tend 
to

have slightly more fat). The real monkey wrench in the works was
absorption rate, which often made nonsense of my calculations. This
may not be as important in therapeutic drugs, for we were aiming at a
specified BAC at a certain time after dosing rather than an average
level.


All those things affect therapeutic dosing.

I may have oversimplified what we are trying to achieve to avoid 
getting bogged down in the detail of what we are trying to achieve and 
provide something people might be able to relate to.


However, we can assume that they are already sorted out, so we know the 
theoretically know what the 'correct' dose is for a patient.  The hard 
bit is unless you want to give everyone liquid so you can measure any 
dose possible you have to have a dose that is a multiple of something 
(Amoxicillin doses in adults are multiples of 250 because thats the size 
of the capsule).


What we are trying to do is determine the most appropriate number to 
make the capsules.  (Our dosing is more complex but lets stick to 
something simple.  I can safely assure you that vritually no-one 
actually needs 250 or 500mg as a dose of amoxicillin... ...thats just a 
dose to get them into a therapeutic window, and I'm 99% certain 250 and 
500 are used coz they are round numbers.  if 337.5 more reliably got 
everyone in the window without kicking anyone out the window that'd be a 
better dose to use!  So... what I'm looking to do is model the 
'theoretical dose required' (which we know) and the dose delivered using 
several starting points to get the 'best fit'.  We know they need to be 
within 7% of each other, but if one starting point can get 85% of doses 
within 5% we think that might be better than one that only gets 50% 
within 5%.



However, I suspect that many therapeutic drugs have a different
dose by weight for children (we weren't dosing children) and choosing
a starting point at the bottom of the range would almost certainly
introduce a systematic error. My intuition would be to anchor the
dosage rate in the middle of the scale and then extrapolate in both
directions (adults only, of course).



We are actually using a starting point that may be middle and going up 
and down if need be.


I think what we may want to do is run a loop through each weight (in 
1kg increments) and calculate their theoretical dose, and the dose for 
each possible starting point (there are certain contraints on that 
already so there may only be 20 possible start points), then we 
calculate the % variance for each dose to theoretical dose and calculate 
the Area Under & Above (some will be negative) the curve and the one 
that has the lowest AUC is then the one that most "precisely" will dose 
the patient...?


__
R-help@r-project.org mailing list
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] puzzling Date math result

2012-04-17 Thread Calum Polwart
  

On Tue, 17 Apr 2012 10:44:40 -0400, Denis Chabot wrote: 

> Hi,
>

> I cannot make a reproducible example easily for my problem, so I'll
>
describe it as best as I can.

YOU KIND OF NEED ONE...

>>
a=test1$période[21]
> 
>> b=test2$date[22]
> a f
> argin-left:5px;
width:100%">b 
> 
> [1] "2011-04-06"
> 
>> 

THIS IS WHY YOU NEED TO
GIVE US A REPRODUCABLE MEANS BECAUSE IF I SIMPLY DO A="2011-04-06" AND
B="2011-04-06" I'M GOING TO GET A==B TRUE

WHERE IS THE DATA IN THE DF'S
BEING SOURCED FROM? IS IT A DATABASE? COULD THERE BE DIFFERENT DATA
DEFINITIONS? IS ITS A CSV FILE ETC? 

and then thi> ft:#1010ff 2px
solid; margin-left:5px; width:100%">as.integer(a) 
> 
> [1] 15070
> 
>>
as.integer(b)
> 
> [1] 15070
> 
> SUGGESTION THAT MIGHT POINT YOU IN A
DIRECTION...
> 
> as.integer (15070)
pre> 

as.integer (15070.1)

[1]
15070

as.integer (15070)==as.integer(15070.1)

[1]
TRUE

15070==15070.1

[1] FALSE

SECOND SUGGESTION WOULD BE TO DROP THE
É NO IDEA WHY THAT WOULD CAUSE A PROBLEM (OR WHERE), BUT ANYTHING THATS
NOT A-Z OR A-Z ONLY INTRODUCES A POTENTIAL EXTRA HEADACHE...

 
as.integer(a)==as.integer(b) 

> 

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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.