Re: [R] How to save and restore a workspace

2017-10-23 Thread Jim Lemon
Hi Jon,
Saving your workspace doesn't mean that everything will be rerun when
you start a new R session. I just means that persistent objects like
data frames will be there. If you type:

objects()

you will see all of those things that were there when you ended in the
last session. Things like commands will be in the "history", so you
can retrieve them just as you did at the end of the last session (up
arrow). It may be a better solution if you save sequences of commands
as R script files (e.g. "something.R") as you can run them:

source("something.R")

and edit and save them again.

Jim

On Tue, Oct 24, 2017 at 9:12 AM,   wrote:
> Hello,
> I recently downloaded R in hopes of learning to use it for statistics.
> I have promptly run into a problem, as I am unable to save, and later 
> recover, a workspace so I can resume work where I left off.
> I am using Windows.
> I indicate "yes" to the pop up after q().  Then when I later reopen R Console 
> and click on File, I cannot get my prior workspace to appear in the R Console 
> frame so I can resume work.
> In the File drop down menu I have tried Load Workspace, Load History, Display 
> file(s)..., opened R Type: R Workspace with no luck.
> I have read about this in two different books, the R Manual, and R FAQs, used 
> the RGui help function, and still cannot do it.
> I have used Windows for years, but I am ignorant about programming.
> Would appreciate any help you might offer.
> I live in the Denver area, so if there are any local resources you could 
> direct me to, I would be grateful for that as well.
>
> Thank you,
> Jon VanDeventer
>
> Sent from my 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.

__
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] draw a circle with a gradient fill

2017-10-24 Thread Jim Lemon
Hi Alex,
This is harder than it looks for a number of reasons. First you want
to desaturate the colors as you move out, which requires something
more sophisticated than the approximation I have done in the code
below. RGB may not be the best colorspace to use for this. Second is
that when you draw a circle, it isn't a circle, it's a polygon.
Therefore you have to fiddle with the line width and spacing to get it
to look smooth. I hope that this example is helpful, but I am not sure
that it illustrates what you want:

library(plotrix)
plot(c(-15,15),c(-15,15),type="n")
ccolors<-rep(NA,60)
cindex<-1
for(rad in seq(10,0.1,length.out=60)) {
 r<-floor(179+76*rad*rad/1)
 g<-b<-floor(2*rad*rad)
 ccolors[cindex]<-rgb(r/255,g/255,b/255)
 draw.circle(0,0,rad,border=ccolors[cindex],col=NA,
  lwd=3,nv=100+rad*10)
 cindex<-cindex+1
}
ccolors
color.legend(2,-15,15,-13,legend=seq(-40,-110,length.out=5),
 rect.col=ccolors[c(1,22,35,47,60)])

Jim

On Tue, Oct 24, 2017 at 8:56 PM, Alaios via R-help  wrote:
> Hi all,I would like to draw a simple circle where the color gradient follows 
> the rule color = 1/(r^2) where r is the distance from the circle. I would 
> also like to add a color bar with values going from -40 to -110 (and 
> associate those with the color gradient that fills the circle).
> So far I experiemented with draw circle 
> install.packages('plotrix')require(plotrix)colors<-c('#fef0d9','#fdcc8a','#fc8d59','#e34a33','#b3')plot(c(-15,15),c(-15,15),type='n')draw.circle(0,
>  0, 10, nv = 1000, border = NULL, col = colors[1], lty = 1, lwd = 
> 1)draw.circle(0, 0, 8, nv = 1000, border = NULL, col = colors[2], lty = 1, 
> lwd = 1)draw.circle(0, 0, 6, nv = 1000, border = NULL, col = colors[3], lty = 
> 1, lwd = 1)draw.circle(0, 0, 4, nv = 1000, border = NULL, col = colors[4], 
> lty = 1, lwd = 1)draw.circle(0, 0, 2, nv = 1000, border = NULL, col = 
> colors[5], lty = 1, lwd = 1)
>
> but this package does not give easily color gradients and so my solutions 
> contains 5 same colors filled rings.
> Will there be any suggested improvements on my code above?
> Thanks a lotAlex
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Scatterplot3d :: Rotating x tick labels by x degrees

2017-10-31 Thread Jim Lemon
Well, scatterplot3d might not allow it, but have a look at the second
example for staxlab in the plotrix package.

Jim

On Wed, Nov 1, 2017 at 7:30 AM, Uwe Ligges
 wrote:
>
>
> On 31.10.2017 00:56, Alex Restrepo wrote:
> ...
> 45 degree rotation is not supported in base R graphics and scatterplot3d
> uses that.
>

__
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 Converting Calendars

2017-11-08 Thread Jim Lemon
Or if you want a slightly prettier output:

formatDate<-function(x) {
 return(paste(x$year,formatC(x$month,width=2,flag=0),
 formatC(x$day,width=2,flag=0),sep="-"))
}
formatDate(p.dates)

Jim


On Thu, Nov 9, 2017 at 10:32 AM, David L Carlson  wrote:
> How about
>
>> p_dates <- paste0(p.dates[[3]], "-", p.dates[[2]], "-", p.dates[[1]])
>> myData$p_dates <- p_dates
>> print(myData, right=FALSE)
>   dates  p_dates
> 1 2017-10-01 1396-7-9
> 2 2017-10-02 1396-7-10
> 3 2017-10-03 1396-7-11
>> str(myData)
> 'data.frame':   3 obs. of  2 variables:
>  $ dates  : Date, format: "2017-10-01" "2017-10-02" ...
>  $ p_dates: chr  "1396-7-9" "1396-7-10" "1396-7-11"
>
> But p_dates is a character field so it will not work with numeric expressions:
>
>> with(myData, dates[3] - dates[1])
> Time difference of 2 days
> # But
>> with(myData, p_dates[3] - p_dates[1])
> Error in p_dates[3] - p_dates[1] :
>   non-numeric argument to binary operator
>
> -
> David L. Carlson
> Department of Anthropology
> Texas A&M University
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Reichman
> Sent: Wednesday, November 8, 2017 5:05 PM
> To: r-help@r-project.org
> Subject: [R] Help Converting Calendars
>
> R-Help
>
> Trying  to convert a Gregorian calendar dataset to a Persian calendar
> dataset.  But I end up with a list and not sure what to do.  For example ...
>
> dates <- c("2017-10-1","2017-10-2","2017-10-3")
> myData <- data.frame(dates)
> myData$dates <- as.Date(myData$dates, format = "%Y-%m-%d")
>> myData
>dates
> 1 2017-10-01
> 2 2017-10-02
> 3 2017-10-03
> library(ConvCalendar)
> p.dates <- as.OtherDate(myData$dates,"persian")
> # after convering I get the following list
>> p.dates
> $day
> [1]  9 10 11
>
> $month
> [1] 7 7 7
>
> $year
> [1] 1396 1396 1396
>
> attr(,"row.names")
> [1] 1 2 3
> attr(,"class")
> [1] "OtherDate"
> attr(,"calendar")
> [1] "persian"
>
> How do I take that,  to end up with
>
>datesp_dates
> 1 2017-10-011396-7-9
> 2 2017-10-021396-7-10
> 3 2017-10-031396-7-11
>
> Jeff Reichman
> Penn State
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to label station names on point

2017-11-13 Thread Jim Lemon
Hi Javad,
You can place text using the "text" function or for a slightly fancier
label, try boxed.labels in the plotrix package.

Jim


On Mon, Nov 13, 2017 at 5:04 PM, Javad Bayat via R-help
 wrote:
> I have a shapefile point and I plot it over my polygon. Is it possible to 
> label station names over points?Sincerely.
> S_Point = readOGR(".","point")plot(S_Point,add=TRUE,col="black",pch=20,cex=2)
>
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Converting a string to variable names

2017-11-14 Thread Jim Lemon
Hi Ruiyang,
I think you want "get":

For (index in seq(1,16)){
plot(x=(a given set of value),y=get(paste(“PC”,as.character(index),sep=“”)))
}

On Wed, Nov 15, 2017 at 7:43 AM, 刘瑞阳  wrote:
> Hi,
> Suppose that I want to do a series of plots with the y value for each plot as 
> PC1, PC2, PC3… How could I accomplish this using a for loop?
> Suppose the code like this:
>
> For (index in seq(1,16)){
> plot(x=(a given set of value),y=paste(“PC”,as.character(index),sep=“”)
> }
>
> But this would not work because y is assigned a string instead of the 
> variable names. So how could I assign y with a variable name instead of a 
> string? Your reply would be appreciated!
> Ruiyang Liu
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] Converting a string to variable names

2017-11-15 Thread Jim Lemon
Hi Ruiyang,
In this case you don't want the "get", just the strings produced by "paste":

mydf<-data.frame(col1=LETTERS[1:10],col2=1:10)
rownames(mydf)<-paste("P",mydf$col1,sep="")

Jim

On Thu, Nov 16, 2017 at 9:22 AM, 刘瑞阳  wrote:
> Hi,
>
> Thanks for your reply.
>
> I just came up with another question about a similar but different thing:
>
> Say I have a bunch of data.frame variables named P1,P2,P3… I want to assign 
> them row names according to symbols in the first column, and I want to do 
> this using a for loop. How could I accomplish this?
>
>
> for (test_sample in c(1:10)){
> + x<-as.name(paste(“P",as.character(test_sampel),sep=""))
> + rownames(x)<-get((paste(“P”,as.character(test_sample),sep="")))[,1]
> + }
>
> This would not work probably because x is simply a name instead of a 
> data.frame variable(Error: "attempt to set 'rownames' on an object with no 
> dimensions"). But I could not find the right way out… How should I solve it?
>
> Thanks!
>
> Ruiyang
>
>
>> On Nov 14, 2017, at 4:39 PM, Jim Lemon  wrote:
>>
>> Hi Ruiyang,
>> I think you want "get":
>>
>> For (index in seq(1,16)){
>> plot(x=(a given set of value),y=get(paste(“PC”,as.character(index),sep=“”)))
>> }
>>
>> On Wed, Nov 15, 2017 at 7:43 AM, 刘瑞阳  wrote:
>>> Hi,
>>> Suppose that I want to do a series of plots with the y value for each plot 
>>> as PC1, PC2, PC3… How could I accomplish this using a for loop?
>>> Suppose the code like this:
>>>
>>> For (index in seq(1,16)){
>>> plot(x=(a given set of value),y=paste(“PC”,as.character(index),sep=“”)
>>> }
>>>
>>> But this would not work because y is assigned a string instead of the 
>>> variable names. So how could I assign y with a variable name instead of a 
>>> string? Your reply would be appreciated!
>>> Ruiyang Liu
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] Fw: modified mankendal

2017-11-23 Thread Jim Lemon
Hi Elham,
The error message is pretty explicit. Check your dataset for missing values.

Jim

On Thu, Nov 23, 2017 at 6:14 AM, Elham Fakharizade via R-help
 wrote:
>
>  Hello DearI used modifiedmk package for trend analyses.this is my script
>  require(modifiedmk)X1<-read.table("c:/elham/first 
> article/r/Spring_NDVI-1.txt",skip=2,header=FALSE)d=dim(X1)
> outMK<-matrix(-999,nrow=4,ncol=d[2])for (c in 
> 1:d[2]){MK<-tfpwmk(X1[,c])outMK[1,c]<-getElement(MK,"S")outMK[2,c]<-getElement(MK,"Var(S)")outMK[3,c]<-getElement(MK,"Sen's
>  Slope")outMK[4,c]<-getElement(MK,"P-value")} unfortunetally I got this error:
> Error in if (S == 0) { : missing value where TRUE/FALSE needed
> would you please help me to solve itSincerely yoursElham
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fw: modified mankendal

2017-11-24 Thread Jim Lemon
Hi Elham,
The error message:

Error in if (S == 0) { : missing value where TRUE/FALSE needed

means that for at least one S, the value is missing. The best advice I
can give you is to load the data frame X1 as in your code above, and
try something like:

which.na<-function(x) return(which(is.na(x)))
sapply(X1,which.na)

You will then get a list of the positions of any NA values in X1.

Jim

On Fri, Nov 24, 2017 at 7:45 PM, Elham Fakharizade  wrote:
> Hello Dear Jim
> Thanks for your answering
> I have more than 65000 data in my file I search for NA or NAN but nothing
> find. how can I search for missing value?
> Sincerely yours
> Elham
>
> Elham Fakharizadeshirazi.
>
> Doctoral guest researcher in Institute of Meteorology,
>
> Department of Earth Sciences,
>
> Free university of Berlin,
>
> Berlin, Germany.
>
>
>
> On Friday, November 24, 2017, 4:33:12 AM GMT+1, Jim Lemon
>  wrote:
>
>
> Hi Elham,
> The error message is pretty explicit. Check your dataset for missing values.
>
> Jim
>
> On Thu, Nov 23, 2017 at 6:14 AM, Elham Fakharizade via R-help
>  wrote:
>>
>>  Hello DearI used modifiedmk package for trend analyses.this is my script
>>  require(modifiedmk)X1<-read.table("c:/elham/first
>> article/r/Spring_NDVI-1.txt",skip=2,header=FALSE)d=dim(X1)
>> outMK<-matrix(-999,nrow=4,ncol=d[2])for (c in
>> 1:d[2]){MK<-tfpwmk(X1[,c])outMK[1,c]<-getElement(MK,"S")outMK[2,c]<-getElement(MK,"Var(S)")outMK[3,c]<-getElement(MK,"Sen's
>> Slope")outMK[4,c]<-getElement(MK,"P-value")} unfortunetally I got this
>> error:
>> Error in if (S == 0) { : missing value where TRUE/FALSE needed
>> would you please help me to solve itSincerely yoursElham
>
>>
>>
>>
>>[[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Scatterplot of many variables against a single variable

2017-11-27 Thread Jim Lemon
Hi Engin,
Sadly, your illustration was ambushed on the way to the list. Perhaps
you want something like this:

# proportion of useful answers to your request
pua<-sort(runif(20))
#legibility of your request
lor<-sort(runif(20))+runif(20,-0.5,0.5)
# is a data set provided?
dsp<-sort(runif(20))+runif(20,-0.5,0.5)
# generate a linear model for the above
pua.lm<-lm(pua~lor+dsp)
# get the coefficients
pua.lm

Call:
lm(formula = pua ~ lor + dsp)

Coefficients:
(Intercept)  lor  dsp
0.1692   0.6132   0.3311

plot(pua~lor,col="red",main="Proportion of useful answers by request quality")
points(pua~dsp,col="blue",pch=2)
abline(0.1692,0.6132,col="red")
abline(0.1692,0.3311,col="blue")

So, the more readable your request and the quality of the data that
you provide, the more useful answers you are likely to receive.

Jim


On Mon, Nov 27, 2017 at 7:56 PM, Engin YILMAZ  wrote:
> Dear
>
> I try to realize one scatter matrix which draws *one single variable to all
> variables* with *regression line* . You can see my eviews version  in the
> annex .
>
> How can I draw this graph with R studio?
>
>
> Sincerely
> Engin YILMAZ
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Data cleaning & Data preparation, what do R users want?

2017-11-29 Thread Jim Lemon
Hi Robert,
People want different levels of automation in the software they use.
What concerns many of us is the desire for the function
"figure-out-what-this-data-is-import-it-and-get-rid-of-bad-values".
Such users typically want something that justifies its use by being
written by someone who seems to know what they're doing and lots of
other people use it. One advantage of many R functions is their
modular construction. This encourages users to at least consider the
steps that are taken rather than just accept what comes out of that
long tube.

Take the contentious problem of outlier identification. If I just let
the black box peel off some values, I don't know what I have lost. On
the other hand, if I import data and examine it with a summary
function, I may find that one woman has a height of 5.2 meters. I can
range check by looking up the Guinness Book of Records. It's an
outlier. I can estimate the probability of such a height.  Hmm, about
4 standard deviations above the mean. It's an outlier. I can attempt a
Sherlock Holmes. "Watson, I conclude that an imperial measure (5'2")
has been recorded as a metric value". It's not an outlier.

The more R gravitates toward "black box" functions, the more some
users are encouraged to let them do the work.You pays your money and
you takes your chances.

Jim


On Thu, Nov 30, 2017 at 3:37 AM, Robert Wilkins  wrote:
> R has a very wide audience, clinical research, astronomy, psychology, and
> so on and so on.
> I would consider data analysis work to be three stages: data preparation,
> statistical analysis, and producing the report.
> This regards the process of getting the data ready for analysis and
> reporting, sometimes called "data cleaning" or "data munging" or "data
> wrangling".
>
> So as regards tools for data preparation, speaking to the highly diverse
> audience mentioned, here is my question:
>
> What do you want?
> Or are you already quite happy with the range of tools that is currently
> before you?
>
> [BTW,  I posed the same question last week to the r-devel list, and was
> advised that r-help might be a more suitable audience by one of the
> moderators.]
>
> Robert Wilkins
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Data cleaning & Data preparation, what do R users want?

2017-11-29 Thread Jim Lemon
Hi again,
Typo in the last email. Should read "about 40 standard deviations".

Jim

On Thu, Nov 30, 2017 at 10:54 AM, Jim Lemon  wrote:
> Hi Robert,
> People want different levels of automation in the software they use.
> What concerns many of us is the desire for the function
> "figure-out-what-this-data-is-import-it-and-get-rid-of-bad-values".
> Such users typically want something that justifies its use by being
> written by someone who seems to know what they're doing and lots of
> other people use it. One advantage of many R functions is their
> modular construction. This encourages users to at least consider the
> steps that are taken rather than just accept what comes out of that
> long tube.
>
> Take the contentious problem of outlier identification. If I just let
> the black box peel off some values, I don't know what I have lost. On
> the other hand, if I import data and examine it with a summary
> function, I may find that one woman has a height of 5.2 meters. I can
> range check by looking up the Guinness Book of Records. It's an
> outlier. I can estimate the probability of such a height.  Hmm, about
> 4 standard deviations above the mean. It's an outlier. I can attempt a
> Sherlock Holmes. "Watson, I conclude that an imperial measure (5'2")
> has been recorded as a metric value". It's not an outlier.
>
> The more R gravitates toward "black box" functions, the more some
> users are encouraged to let them do the work.You pays your money and
> you takes your chances.
>
> Jim
>
>
> On Thu, Nov 30, 2017 at 3:37 AM, Robert Wilkins  wrote:
>> R has a very wide audience, clinical research, astronomy, psychology, and
>> so on and so on.
>> I would consider data analysis work to be three stages: data preparation,
>> statistical analysis, and producing the report.
>> This regards the process of getting the data ready for analysis and
>> reporting, sometimes called "data cleaning" or "data munging" or "data
>> wrangling".
>>
>> So as regards tools for data preparation, speaking to the highly diverse
>> audience mentioned, here is my question:
>>
>> What do you want?
>> Or are you already quite happy with the range of tools that is currently
>> before you?
>>
>> [BTW,  I posed the same question last week to the r-devel list, and was
>> advised that r-help might be a more suitable audience by one of the
>> moderators.]
>>
>> Robert Wilkins
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fwd: Wanted to learn R Language

2017-11-30 Thread Jim Lemon
Hi SAS_learner,
Have a look at the read.xport function in the foreign package.

Jim

On Fri, Dec 1, 2017 at 7:50 AM, SAS_learner  wrote:
> Hello all ,
>
> I am a SAS user for a while and wanted to learn to program in R . My
> biggest hurdle to start, is to get the data (I work in clinical domain
> ) that too inside VPN secured access. The only way I can learn during
> my work time is create my own data frames and create programs that can
> be used for data ( either SDTM or AdAM data ) validation or checking
> Table counts . For this I need to imitate the clinical data structure
> . If there is any place or a package that help to start. I have couple
> of dummy SAS datasets in my work area , but not sure how can I can
> access them . Can anybody help me . Thanks ahead .
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Coeficients estimation in a repeated measures linear model

2017-12-06 Thread Jim Lemon
Hi Sergio,
You seem to be aiming for a univariate repeated measures analysis.
Maybe this will help:

subno<-rep(1:6,2)
dat <- data.frame(subno=rep(1:6,2),,vals = c(ctrl, ttd),
   cond = c(rep("ctrl", 6), rep("ttd", 6)), ind = factor(rep(1:6, 2)))
fit<-aov(vals~ind+cond+Error(subno),data=dat)
fit
summary(fit)

Note that the assumptions of this model are easy to violate.

Jim


On Thu, Dec 7, 2017 at 1:17 AM, Sergio PV  wrote:
> Dear Users,
>
> I am trying to understand the inner workings of a repeated measures linear
> model. Take for example a situation with 6 individuals sampled twice for
> two conditions (control and treated).
>
> set.seed(12)
> ctrl <- rnorm(n = 6, mean = 2)
> ttd <- rnorm(n = 6, mean = 10)
> dat <- data.frame(vals = c(ctrl, ttd),
>   group = c(rep("ctrl", 6), rep("ttd", 6)),
>   ind = factor(rep(1:6, 2)))
>
> fit <- lm(vals ~ ind + group, data = dat)
> model.matrix(~ ind + group, data = dat)
>
> I am puzzled on how the coeficients are calculated. For example, according
> to the model matrix, I thought the intercept would be individual 1 control.
> But that is clearly not the case.
> For the last coeficient, I understand it as the mean of all differences
> between treated vs control at each individual.
>
> I would greatly appreciate if someone could clarify to me how the
> coefficients in this situation are estimated.
>
> Thanks
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Draw Overlapping Circles with shaded tracks

2017-12-29 Thread Jim Lemon
Hi Abou,
Without an illustration it's hard to work out what you want. here is a
simple example of two circles using semi-transparency. Is this any
help?

pdf("circles.pdf")
plot(0:10,type="n",axes=FALSE,xlab="",ylab="")
draw.circle(4,5,radius=3,border="#ffaa",lwd=10)
draw.circle(6,5,radius=3,border="#ffaa",lwd=10)
dev.off()

Jim

On Fri, Dec 29, 2017 at 9:45 PM, AbouEl-Makarim Aboueissa
 wrote:
> Dear All:
>
>
> I am wondering if there is a way in R to draw these two circles with shaded
> tracks in both circles using R, and make both circles uncovered. I am
> trying to make it in MS words, but I could not. Your help will be highly
> appreciated.
>
>
> In my previous post I added the image of the two circles, but the post
> never published. I just thought to resent the post again without the image.
>
> with many thanks
> abou
> __
>
>
> *AbouEl-Makarim Aboueissa, PhD*
>
> *Professor of Statistics*
>
> *Department of Mathematics and Statistics*
> *University of Southern Maine*
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Draw Overlapping Circles with shaded tracks

2017-12-31 Thread Jim Lemon
Hi Abou,
Sure:

library(plotrix)
pdf("circles.pdf")
plot(0:10,type="n",axes=FALSE,xlab="",ylab="")
ymult=getYmult()
draw.circle(4,5,radius=3,border="#ffaa",lwd=10)
for(angle in seq(0,1.95*pi,by=0.05*pi))
 draw.circle(4+3*cos(angle),5+3*sin(angle)*ymult,
  radius=runif(1,0.05,0.1),col="#00ff00aa")
draw.circle(6,5,radius=3,border="#ffaa",lwd=10)
for(angle in seq(0,1.95*pi,by=0.05*pi))
 draw.circle(6+3*cos(angle),5+3*sin(angle)*ymult,
  radius=runif(1,0.05,0.1),col="#00aa")
dev.off()

You're right, it's really ugly.

Thanks John, how could I have forgotten.

Jim

On Mon, Jan 1, 2018 at 1:13 AM, AbouEl-Makarim Aboueissa
 wrote:
> Dear All:
>
> Thank you very much for all of you.
>
> I just have one more thing. Is there a way to fill the borders with small
> dots, may be different sizes.
>
> I tried to do it, but it looks ugly.
>
> Here what I tried:
>
>
>
>
> library(plotrix)
>
>
> plot(0:10, 0:10, type="n",axes=FALSE,xlab="",ylab="")    0:5,
>
> draw.circle(4,5,radius=3,border="#ffaa", lwd=75)
>
> draw.circle(4,5,radius=2.50,border="red",lty=3,lwd=3)
> draw.circle(4,5,radius=2.55,border="red",lty=3,lwd=3)
> draw.circle(4,5,radius=2.60,border="red",lty=3,lwd=3)
> draw.circle(4,5,radius=2.65,border="red",lty=3,lwd=3)
> draw.circle(4,5,radius=2.70,border="red",lty=3,lwd=3)
>
> draw.circle(4,5,radius=2.75,border="red",lty=3,lwd=3)
> draw.circle(4,5,radius=2.80,border="red",lty=3,lwd=3)
> draw.circle(4,5,radius=2.85,border="red",lty=3,lwd=3)
> draw.circle(4,5,radius=2.90,border="red",lty=3,lwd=3)
> draw.circle(4,5,radius=2.95,border="red",lty=3,lwd=3)
> draw.circle(4,5,radius=3.0,border="red",lty=3,lwd=3)
>
> draw.circle(4,5,radius=3.05,border="red",lty=3,lwd=3)
> draw.circle(4,5,radius=3.10,border="red",lty=3,lwd=3)
> draw.circle(4,5,radius=3.15,border="red",lty=3,lwd=3)
> draw.circle(4,5,radius=3.20,border="red",lty=3,lwd=3)
> draw.circle(4,5,radius=3.25,border="red",lty=3,lwd=3)
>
>
> draw.circle(4,5,radius=3.30,border="red",lty=3,lwd=3)
> draw.circle(4,5,radius=3.35,border="red",lty=3,lwd=3)
> draw.circle(4,5,radius=3.40,border="red",lty=3,lwd=3)
> draw.circle(4,5,radius=3.45,border="red",lty=3,lwd=3)
> draw.circle(4,5,radius=3.50,border="red",lty=3,lwd=3)
>
>
>
> draw.circle(7.5,5,radius=3,border="#ffaa",lwd=75)
>
>
> draw.circle(7.5,5,radius=2.50,border="blue",lty=3,lwd=3)
> draw.circle(7.5,5,radius=2.55,border="blue",lty=3,lwd=3)
> draw.circle(7.5,5,radius=2.60,border="blue",lty=3,lwd=3)
> draw.circle(7.5,5,radius=2.65,border="blue",lty=3,lwd=3)
> draw.circle(7.5,5,radius=2.70,border="blue",lty=3,lwd=3)
>
> draw.circle(7.5,5,radius=2.75,border="blue",lty=3,lwd=3)
> draw.circle(7.5,5,radius=2.80,border="blue",lty=3,lwd=3)
> draw.circle(7.5,5,radius=2.85,border="blue",lty=3,lwd=3)
> draw.circle(7.5,5,radius=2.90,border="blue",lty=3,lwd=3)
> draw.circle(7.5,5,radius=2.95,border="blue",lty=3,lwd=3)
> draw.circle(7.5,5,radius=3.0,border="blue",lty=3,lwd=3)
>
> draw.circle(7.5,5,radius=3.05,border="blue",lty=3,lwd=3)
> draw.circle(7.5,5,radius=3.10,border="blue",lty=3,lwd=3)
> draw.circle(7.5,5,radius=3.15,border="blue",lty=3,lwd=3)
> draw.circle(7.5,5,radius=3.20,border="blue",lty=3,lwd=3)
> draw.circle(7.5,5,radius=3.25,border="blue",lty=3,lwd=3)
>
>
> draw.circle(7.5,5,radius=3.30,border="blue",lty=3,lwd=3)
> draw.circle(7.5,5,radius=3.35,border="blue",lty=3,lwd=3)
> draw.circle(7.5,5,radius=3.40,border="blue",lty=3,lwd=3)
> draw.circle(7.5,5,radius=3.45,border="blue",lty=3,lwd=3)
> draw.circle(7.5,5,radius=3.50,border="blue",lty=3,lwd=3)
>
>
>
> Once again thank you very much
>
> abou
>
> __
>
>
> *AbouEl-Makarim Aboueissa, PhD*
>
> *Professor of Statistics*
>
> *Department of Mathematics and Statistics*
> *University of Southern Maine*
>
>
> On Sun, Dec 31, 2017 at 8:40 AM, Marc Girondot via R-help <
> r-help@r-project.org> wrote:
>
>> Another solution:
>>
>> library("HelpersMG") plot(0:10,type="n",axes=FALSE,xlab="",ylab="",
>> asp=1) ellipse(center.x = 3, center.y = 5, radius.x = 5, radius.y = 5,
>> lwd=10, col=NA, border=rgb(red = 1, gree

Re: [R] barplot_add=TRUE

2018-01-09 Thread Jim Lemon
Hi Sibylle,
I might have the wrong idea, but does this:

hecke<-matrix(sample(1:40,104,TRUE),nrow=2)
library(plotrix)
barp(hecke,col=c("lightblue","pink"))
legend(43,40,c("M","F"),fill=c("lightblue","pink"))

do what you want? It is also possible to display this as a nested bar
plot showing males and females within total catch.

Jim


On Tue, Jan 9, 2018 at 7:19 PM, Sibylle Stöckli  wrote:
> Dear R users
>
> aim
> Barplot of insect trap catches (y variable trapcatch) at one specific station 
> (variable FiBL_Hecke) from week 1-52 ( x variable week).
> It works well using the function tapply (sum trapcatch per week, males and 
> females not separated), however, I intend to separate the y variable 
> trapcatch in males and females (variable m_w: m and w)
>
> problem
> I used the function "add" to merge two bar plots (males and females). 
> Unfortunately the second barplot masks the first barplot.
>
> question
> Is there a function to "mathematically" add the values from both barplots 
> with the aim the barplot presenting the total trap (males and females) 
> catches per week?
>
>
>
> Hecke<-trap[trap$station=="FiBL_Hecke",] # station = Hecke
> m<-Hecke[Hecke$m_w=="m",] # male trap catches
> w<-Hecke[Hecke$m_w=="w",] # female trap catches
>
> barplot(m$trapcatch, ylab="Y", space=0.5, col=c("grey0"), ylim=c(0,450), 
> las=2, cex.lab=0.9, cex.axis=0.9, cex.names=0.9)
> barplot(w$trapcatch,space=0.5, add=TRUE, beside=FALSE, col=c("grey50"), 
> xaxt="n", yaxt="n")
>
> Thanks a lot
> Sibylle
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] barplot that displays sums of values of 2 y colums grouped by different variables

2018-01-15 Thread Jim Lemon
Hi Kenneth,
I don't know about ggplot, but perhaps this will help:

kddf<-read.table(text="city n y
mon 100 200
tor 209 300
edm 98 87
mon 20 76
tor 50 96
edm 62 27",
header=TRUE,stringsAsFactors=FALSE)
library(plotrix)
barpos<-barp(t(kddf[,2:3]),names.arg=kddf[,1],xlab="City",ylab="Sum",
 main="Sums of values of 2 y columns",col=2:3)
legend(5,300,c("Sum of n","Sum, of y"),fill=2:3)
barlabels(barpos$x,barpos$y)

Jim


On Tue, Jan 16, 2018 at 3:59 AM, kenneth dyson
 wrote:
> I am trying to create a barplot displaying the sums of 2 columns of data
> grouped by a variable. the data is set up like this:
>
> "city" "n" "y" 
> mon 100 200 
> tor 209 300 
> edm 98 87 
> mon 20 76 
> tor 50 96 
> edm 62 27 
>
> the resulting plot should have city as the x-axis, 2 bars per city, 1
> representing the sum of "n" in that city, the other the sum of "y" in that
> city.
>
> If possible also show the sum in each bar as a label?
>
> I aggregated the data into sums like this:
>
> sum_data <- aggregate(. ~ City,data=raw_data,sum)
>
> this gave me the sums per city as I wanted but for some reason 1 of the
> cities is missing in the output.
>
> Using this code for the plot:
>
> ggplot(sum_data,aes(x = City,y = n)) + geom_bar(aes(fill = y),stat =
> "identity",position = "dodge")
>
> gave be a bar plot with one bar per city showing the sum of y as a color
> gradient. not what I expected given the "dodge" command in geom_bar.
>
> 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.

__
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] Leaflet maps. Nudging co-incident markers

2018-01-20 Thread Jim Lemon
Hi Gavin,
Here's a sort of brute force way to nudge points. Might be helpful.

nudge<-function(x,y,away=0.1,tol=0.01) {
 dimx<-dim(x)
 if(missing(y) && !is.null(dimx)) {
  y<-x[,2]
  x<-x[,1]
 }
 xlen<-length(x)
 if(xlen != length(y)) stop("x and y must be the same length.")
 for(i in 1:xlen) {
  for(j in 1:xlen) {
   if(i != j) {
dist<-sqrt((x[i]-x[j])^2 + (y[i]-y[j])^2)
if(dist < tol) {
 if(x[i] >= x[j]) {
  x[i]<-x[i]+away
  x[j]<-x[j]-away
 } else {
  x[i]<-x[i]-away
  x[j]<-x[j]+away
 }
 if(y[i] >= y[j]) {
  y[i]<-y[i]+away
  y[j]<-y[j]-away
 } else {
  y[i]<-y[i]-away
  y[j]<-y[j]+away
 }
}
   }
  }
 }
 return(list(x=x,y=y))
}
x=c(-1.9116, -1.9116,-1.9237,-1.91848)
y=c(52.4898,52.4898,52.5015,52.4851)
plot(nudge(x,y,0.0001,0.1))

Jim

On Sat, Jan 20, 2018 at 4:51 AM, Gavin Rudge (Institute of Applied
Health Research)  wrote:
> I have a dataset showing points, with a category for each point and its 
> location.
>
> I simply want to display my points, in a way that users can toggle the points 
> on and off by category.
>
> Where I have two objects in the same category I'd like to display them nudged 
> to appear as two distinct, but very close points.
> I have made reproduceable example (the places are not real), which is loosely 
> based on a tutorial I found recently 
> (https://allthisblog.wordpress.com/2016/10/12/r-311-with-leaflet-tutorial/)
>
> I have three categories of things (cafes, libraries and galleries), at three 
> locations but have four objects in my set. This is because on of my locations 
> has two functions - there is a cafe at a gallery (North St Gallery and the 
> Gallery Cafe on the same site)
>
> If I make a selection that includes galleries and cafes there are just two 
> points. I would like to nudge the point for the North St Galley and the 
> Gallery Cafe so they appear as two (very close) points on the map and display 
> the name when clicked on.
>
> Also if anyone has any suggestions for generally tidying up the code I'd be 
> grateful as my real version is much more complex with many more points and 
> marker categories.   I believe there are Java libraries out there for 
> managing markers and how they behave, but I'm hoping this can be done in the 
> Leaflet R library somehow.
>
> The only solution I could think of was to interrogate the entire dataframe, 
> identify points that were had the same co-ords and move them diagonally apart 
> by adding and subtracting a fixed amount of longitude and latitude from the 
> co-ordinates.
>
> Thanks in advance.
>
> GavinR
>
> Here is the code:
>
> library(leaflet)
>
> #make data frame of points
>
> idno=c(1,2,3,4)
> x=c(-1.9116, -1.9116,-1.9237,-1.91848)
> y=c(52.4898,52.4898,52.5015,52.4851)
> cat=c('Gallery','Cafe','Library','Cafe')
> n=c('North St Gallery','Gallery cafe', 'South St Library', 'Coffee 2 go')
> d<-data.frame(idno,x,y,cat,n)
>
> #get a map and zoom into approx area of interest
>
> m=leaflet()%>% setView(lng = -1.935, lat=52.485, zoom=12)
> m=addTiles(m)
> m
>
> #create groups of objects
>
> c= subset(d,cat=="Cafe")
> l= subset(d, cat=="Library")
> g= subset(d, cat=="Gallery")
>
> #add markers
>
> m=addCircleMarkers(m,
>  lng = c$x,
>  lat = c$y,
>  popup = c$n,
>  radius = 5,
>  stroke =FALSE,
>  fillOpacity = 0.75,
>  group = "1 - Cafes")
>
> m=addCircleMarkers(m,
>lng = g$x,
>lat = g$y,
>popup = g$n,
>radius = 5,
>stroke =FALSE,
>fillOpacity = 0.75,
>group = "2 - Galleries")
>
> m=addCircleMarkers(m,
>lng = l$x,
>lat = l$y,
>popup = l$n,
>radius = 5,
>stroke =FALSE,
>fillOpacity = 0.75,
>group = "3 - libraries")
>
> m = addLayersControl(m, overlayGroups = c("1 - Cafes","2 - Galleries","3 - 
> libraries"))
>
> m
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Manipulating two large dataset differing by date and time

2018-01-21 Thread Jim Lemon
Hi Ogbos,
You can just use ISOdate. If you pass more values, it will process them:

ISOdate(2018,01,22)
[1] "2018-01-22 12:00:00 GMT"
> ISOdate(2018,01,22,18,17)
[1] "2018-01-22 18:17:00 GMT"

Add something like:

if(is.null(data$hour),data$hour<-12

then pass data$hour as it will default to the same value as if you
hadn't passed it.

Jim

On Mon, Jan 22, 2018 at 6:01 PM, Ogbos Okike  wrote:
> Dear Members,
>
> Compliments of the Season!!
>
>
> Below is a part of a code I use for Fourier analysis of signals. The code
> handles data with the format 05 01 018628 (year, month, day and count)
>   05 01 028589 (year, month, day and count)
> The sample data is attached as 2005daily.txt.
>
> I would like to adapt the code to handle data of the form:
> 05 01 01 004009 (year, month, day, hour and count)
> 05 01 01 013969 (year, month, day, hour and count)
>
> The sample is also attached as 2005hourly.txt.
>
> Thank you very much for your kind inputs.
>
> Ogbos
>
>
>
>
> data <- read.table("2005daily.txt", col.names = c("year", "month", "day",
> "counts"))
>
> new.century <- data$year < 50
>
> data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
>
> data$date <- as.Date(ISOdate(data$year, data$month, data$day))
> x1 = data$date
>  y = data$counts
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with the plot overlay

2018-02-04 Thread Jim Lemon
Hi Ace,
You can do it with plotrix:

library(plotrix)
barpos<-barp(c(1,5,38),width=0.5,col=c("white","lightgray","darkgray"),ylim=c(0,70))
ehplot(c(1,0.8,0.9,0.8,1.1,1,4,3,5,14,3,2,32,27,33,30,50,61),
 c(1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3),median=FALSE,add=TRUE,cex=2,
 pch=21,bg="white")
dispersion(barpos$x,barpos$y,c(0.1,1,5),lwd=2,arrow.cap=0.03)
lines(c(barpos$x[2],barpos$x[2],barpos$x[3],barpos$x[3]),c(18,63,63,62))
lines(c(barpos$x[1],barpos$x[1],barpos$x[3],barpos$x[3]),c(4,66,66,65))
text(2,68,"**",cex=2)
text(2.5,64.5,"**",cex=2)

Jim


On Mon, Feb 5, 2018 at 8:56 AM, Fix Ace via R-help  wrote:
> Dear R Community,
> I recently read an article and found a plot as attached. It has scatterplot, 
> barplot, and error bar. Could anyone help me to figure out what package I can 
> use in R to generate such plot?
> Thank you very much for any inputs!
> Kind regards,
> Ace
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help with regular expressions

2018-02-12 Thread Jim Lemon
Hi Dennis,
How about:


# define the two values to search for
x<-2
y<-3
# create your search string and replacement string
repstring<-paste(x,y,sep=",")
newstring<-paste(x,y,sep=".")
# this is the string that you want to change
thetastring<-"SIGMA(2,3)"
sub(repstring,newstring,thetastring)
[1] "SIGMA(2.3)"

Use gsub if you want to change multiple values

Jim

On Tue, Feb 13, 2018 at 1:22 PM, Dennis Fisher  wrote:
> R 3.4.2
> OS X
>
> Colleagues
>
> I would appreciate some help with regular expressions.
>
> I have string that looks like:
> " ITERATION  ,THETA1 ,THETA2  
>,THETA3 ,THETA4 ,THETA5 
> ,THETA6 ,THETA7 ,SIGMA(1,1) 
> ,SIGMA(2,1) ,SIGMA(2,2)”
>
> In the entries that contain:
> (X,Y)   # for example, SIGMA(1,1)
> I would like to replace the comma with a period, e.g., SIGMA(1.1) but NOT the 
> other commas
>
> The end-result would be:
> " ITERATION  ,THETA1 ,THETA2  
>,THETA3 ,THETA4 ,THETA5 
> ,THETA6 ,THETA7 ,SIGMA(1.1) 
> ,SIGMA(2.1) ,SIGMA(2.2)”
>
> Can someone provide the regular expression code to accomplish this?
> Thanks.
>
> 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.


Re: [R] include

2018-02-23 Thread Jim Lemon
Hi Val,
Try this:

preval<-data.frame(Col1=unique(unlist(mydat[,c("Col2","col3")]))[-1],
 Col2=NA,col3=NA)
rbind(preval,mydat)

Jim

On Sat, Feb 24, 2018 at 3:34 PM, Val  wrote:
> Hi All,
>
> I am reading a file as follow,
>
> mydat <- read.table(textConnection("Col1 Col2 col3
> Z2 NA NA
> Z3 X1 NA
> Z4 Y1 W1"),header = TRUE)
>
> 1. "NA" are   missing  should be replace by 0
> 2.  value that are in COl2 and Col3  should be included  in col1 before
> they appear
> in col2 and col3. So the output data looks like as follow,
>
> X1  0  0
> Y1  0  0
> W1  0  0
> Z2  0  0
> Z3 X1  0
> Z4 Y1 W1
>
> Thank you in advance
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] include

2018-02-24 Thread Jim Lemon
hi Val,
Your problem seems to be that the data are read in as a factor. The
simplest way I can think of to get around this is:

mydat <- read.table(textConnection("Col1 Col2 col3
Z1 K1 K2
Z2 NA NA
Z3 X1 NA
Z4 Y1 W1"),header = TRUE,stringsAsFactors=FALSE)
preval<-data.frame(Col1=unique(unlist(mydat[,c("Col2","col3")]))[-1],
 Col2=NA,col3=NA)
rbind(preval,mydat)
mydat[is.na(mydat)]<-"0"

Jiim


On Sun, Feb 25, 2018 at 11:05 AM, Val  wrote:
> Sorry , I hit the send key accidentally  here is my complete message.
>
> Thank you Jim   and all, I got it.
>
> I have one more question on the original question
>
>  What does this  "[-1] "  do?
> preval<-data.frame(Col1=unique(unlist(mydat[,c("Col2","col3")]))[-1],
>Col2=NA,col3=NA)
>
>
> mydat <- read.table(textConnection("Col1 Col2 col3
> Z1 K1 K2
> Z2 NA NA
> Z3 X1 NA
> Z4 Y1 W1"),header = TRUE)
>
> preval<-data.frame(Col1=unique(unlist(mydat[,c("Col2","col3")]))[-1],
>Col2=NA,col3=NA)
> rbind(unique(preval),mydat)
>
>
>  Col1 Col2 col3
> 1   
> 2   X1  
> 3   Y1  
> 4   K2  
> 5   W1  
> 6   Z1   K1   K2
> 7   Z2  
> 8   Z3   X1 
> 9   Z4   Y1   W1
>
> I could not find K1 in the first   col1. Is that possible to fix this?
>
> On Sat, Feb 24, 2018 at 5:59 PM, Val  wrote:
>
>> Thank you Jim   and all, I got it.
>>
>> I have one more question on the original question
>>
>>  What does this  "[-1] "  do?
>> preval<-data.frame(Col1=unique(unlist(mydat[,c("Col2","col3")]))[-1],
>>Col2=NA,col3=NA)
>>
>>
>> mydat <- read.table(textConnection("Col1 Col2 col3
>> Z1 K1 K2
>> Z2 NA NA
>> Z3 X1 NA
>> Z4 Y1 W1"),header = TRUE)
>>
>> preval<-data.frame(Col1=unique(unlist(mydat[,c("Col2","col3")]))[-1],
>>Col2=NA,col3=NA)
>> rbind(unique(preval),mydat)
>>
>>
>>  Col1 Col2 col3
>> 1   
>> 2   X1  
>> 3   Y1  
>> 4   K2  
>> 5   W1  
>> 6   Z1   K1   K2
>> 7   Z2  
>> 8   Z3   X1 
>> 9   Z4   Y1   W1
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> On Sat, Feb 24, 2018 at 5:04 PM, Duncan Murdoch 
>> wrote:
>>
>>> On 24/02/2018 1:53 PM, William Dunlap via R-help wrote:
>>>
>>>> x1 =  rbind(unique(preval),mydat)
>>>>x2 <- x1[is.na(x1)] <- 0
>>>>x2  # gives 0
>>>>
>>>> Why introduce the 'x2'?   x1[...] <- 0 alters x1 in place and I think
>>>> that
>>>> altered x1 is what you want.
>>>>
>>>> You asked why x2 was zero.  The value of the expression
>>>> f(a) <- b
>>>> and assignments are processed right to left so
>>>> x2 <- x[!is.na(x1)] <- 0
>>>> is equivalent to
>>>> x[!is.na(x1)] <- 0
>>>> x2 <- 0
>>>>
>>>
>>> That's not right in general, is it?  I'd think that should be
>>>
>>> x[!is.na(x1)] <- 0
>>> x2 <- x1
>>>
>>> Of course, in this example, x1 is 0, so it gives the same answer.
>>>
>>> Duncan Murdoch
>>>
>>>
>>>
>>>>
>>>> Bill Dunlap
>>>> TIBCO Software
>>>> wdunlap tibco.com
>>>>
>>>> On Sat, Feb 24, 2018 at 9:59 AM, Val  wrote:
>>>>
>>>> Thank you Jim
>>>>>
>>>>> I wanted a final data frame  after replacing the NA's to "0"
>>>>>
>>>>> x1 =  rbind(unique(preval),mydat)
>>>>> x2 <- x1[is.na(x1)] <- 0
>>>>> x2
>>>>>   but I got this,
>>>>>
>>>>> [1] 0
>>>>>
>>>>> why I am getting this?
>>>>>
>>>>>
>>>>> On Sat, Feb 24, 2018 at 12:17 AM, Jim Lemon 
>>>>> wrote:
>>>>>
>>>>> Hi Val,
>>>>>> Try this:
>>>>>>
>>>>>> preval<-data.frame(Col1=unique(unlist(mydat[,c("Col2","col3")]))[-1],
>>>>>>   Col2=NA,col3=NA)
>>>>>> rbind(preval,mydat)
>>>>>>
>>>>>> Jim
>>>>>>
>>>>>> On Sat, Feb 24, 2018

Re: [R] include

2018-02-24 Thread Jim Lemon
Hi Val,
My fault - I assumed that the NA would be first in the result produced
by "unique":

mydat <- read.table(textConnection("Col1 Col2 col3
Z1 K1 K2
Z2 NA NA
Z3 X1 NA
Z4 Y1 W1"),header = TRUE,stringsAsFactors=FALSE)
val23<-unique(unlist(mydat[,c("Col2","col3")]))
napos<-which(is.na(val23))
preval<-data.frame(Col1=val23[-napos],
 Col2=NA,col3=NA)
mydat<-rbind(preval,mydat)
mydat[is.na(mydat)]<-"0"
mydat

Jim

On Sun, Feb 25, 2018 at 11:27 AM, Val  wrote:
> Thank you Jim,
>
> I read the data as you suggested but I could not find K1 in   col1.
>
> rbind(preval,mydat)
>   Col1 Col2 col3
> 1   
> 2   X1  
> 3   Y1  
> 4   K2  
> 5   W1  
> 6   Z1   K1   K2
> 7   Z2  
> 8   Z3   X1 
> 9   Z4   Y1   W1
>
>
>
> On Sat, Feb 24, 2018 at 6:18 PM, Jim Lemon  wrote:
>>
>> hi Val,
>> Your problem seems to be that the data are read in as a factor. The
>> simplest way I can think of to get around this is:
>>
>> mydat <- read.table(textConnection("Col1 Col2 col3
>> Z1 K1 K2
>> Z2 NA NA
>> Z3 X1 NA
>> Z4 Y1 W1"),header = TRUE,stringsAsFactors=FALSE)
>> preval<-data.frame(Col1=unique(unlist(mydat[,c("Col2","col3")]))[-1],
>>  Col2=NA,col3=NA)
>> rbind(preval,mydat)
>> mydat[is.na(mydat)]<-"0"
>>
>> Jiim
>>
>>
>> On Sun, Feb 25, 2018 at 11:05 AM, Val  wrote:
>> > Sorry , I hit the send key accidentally  here is my complete message.
>> >
>> > Thank you Jim   and all, I got it.
>> >
>> > I have one more question on the original question
>> >
>> >  What does this  "[-1] "  do?
>> > preval<-data.frame(Col1=unique(unlist(mydat[,c("Col2","col3")]))[-1],
>> >Col2=NA,col3=NA)
>> >
>> >
>> > mydat <- read.table(textConnection("Col1 Col2 col3
>> > Z1 K1 K2
>> > Z2 NA NA
>> > Z3 X1 NA
>> > Z4 Y1 W1"),header = TRUE)
>> >
>> > preval<-data.frame(Col1=unique(unlist(mydat[,c("Col2","col3")]))[-1],
>> >Col2=NA,col3=NA)
>> > rbind(unique(preval),mydat)
>> >
>> >
>> >  Col1 Col2 col3
>> > 1   
>> > 2   X1  
>> > 3   Y1  
>> > 4   K2  
>> > 5   W1  
>> > 6   Z1   K1   K2
>> > 7   Z2  
>> > 8   Z3   X1 
>> > 9   Z4   Y1   W1
>> >
>> > I could not find K1 in the first   col1. Is that possible to fix this?
>> >
>> > On Sat, Feb 24, 2018 at 5:59 PM, Val  wrote:
>> >
>> >> Thank you Jim   and all, I got it.
>> >>
>> >> I have one more question on the original question
>> >>
>> >>  What does this  "[-1] "  do?
>> >> preval<-data.frame(Col1=unique(unlist(mydat[,c("Col2","col3")]))[-1],
>> >>Col2=NA,col3=NA)
>> >>
>> >>
>> >> mydat <- read.table(textConnection("Col1 Col2 col3
>> >> Z1 K1 K2
>> >> Z2 NA NA
>> >> Z3 X1 NA
>> >> Z4 Y1 W1"),header = TRUE)
>> >>
>> >> preval<-data.frame(Col1=unique(unlist(mydat[,c("Col2","col3")]))[-1],
>> >>Col2=NA,col3=NA)
>> >> rbind(unique(preval),mydat)
>> >>
>> >>
>> >>  Col1 Col2 col3
>> >> 1   
>> >> 2   X1  
>> >> 3   Y1  
>> >> 4   K2  
>> >> 5   W1  
>> >> 6   Z1   K1   K2
>> >> 7   Z2  
>> >> 8   Z3   X1 
>> >> 9   Z4   Y1   W1
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> On Sat, Feb 24, 2018 at 5:04 PM, Duncan Murdoch
>> >> 
>> >> wrote:
>> >>
>> >>> On 24/02/2018 1:53 PM, William Dunlap via R-help wrote:
>> >>>
>> >>>> x1 =  rbind(unique(preval),mydat)
>> >>>>x2 <- x1[is.na(x1)] <- 0
>> >>>>x2  # gives 0
>> >>>>
>> >>>> Why introduce the 'x2'?   x1[...] <- 0 alters x1 in place and I think
>> >>>> that
>> >>>> altered x1 is what you want.
>> >>>>

Re: [R] reshaping column items into rows per unique ID

2018-02-25 Thread Jim Lemon
Hi Allaisone,
If you want a data frame as the output you will have to put up with a
few NA values unless each Customer has the same number of diet types:

a1df<-read.table(text="CustomerIDDietType
1   a
1c
1b
2f
2 a
3 j
4 c
4 c
4  f",
header=TRUE,stringsAsFactors=FALSE)
library(prettyR)
stretch_df(a1df,"CustomerID","DietType")
  CustomerID DietType_1 DietType_2 DietType_3
1  1  a  c  b
2  2  f  a   
3  3  j  
4  4  c  c  f

Jim


On Sun, Feb 25, 2018 at 11:59 PM, Allaisone 1  wrote:
> Hi All
>
> I have a datafram which looks like this :
>
> CustomerIDDietType
> 1   a
> 1c
> 1b
> 2f
> 2 a
> 3 j
> 4 c
> 4 c
> 4  f
>
> And I would like to reshape this so I can see the list of DietTypes per 
> customer in rows instead of columns like this :
>
>> MyDf
> CustomerID  DietType   DietType  DietType
> 1ac   b
> 2 f a
> 3 j
> 4 c  c f
>
> I tried many times using melt(),spread (),and dcast () functions but was not 
> able to produce the desired table. The best attempt was by typing :
>
> # 1) Adding new column with unique values:
> MyDf $newcol <- c (1:9)
> #2) then :
> NewDf <- dcast (MyDf,CustomerID~newcol,value.var=DietType)
>
> This produces the desired table but with many NA values like this :
>
> CustomerID1   2   34 56 7   8   9
> 1a  cb   NA NA NA NA NA NA
> 2  NA NA NA  f a  NA NA NA NA
> 3  NA NA NA NA NA  j   NA NA NA
> 4  NA NA NA NA NA NA c c f
>
>   As you see, the lette/s indicating DietType move to the right side each 
> time we move down leaving many NA values and as my original files is very 
> large, I expect that the final output would contain around 800,000 columns 
> and 70,000 rows. This is why my code works with small data but does not work 
> with my large file because of memory issue even though I'm using large PC.
>
> What changes I need to do with my code to produce the desired table where the 
> list of DietTypes are grouped in rows exactly like the second table shown 
> abover?
>
> Regards
> Allaisnoe
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] raster time series statistics

2018-03-05 Thread Jim Lemon
Hi Herry,
This is probably due to a call to strptime (or similar). No, it
doesn't accept %Y-%m as a valid format. Maybe add a constant day to
all the dates as that will work:

dt<-list(ID=seq(1:24),month=rep(formatC(1:12,flag=0,width=2),2),
 year=sort(rep(2016:2017,12)))
timelst<-paste(unlist(dt['year']),unlist(dt['month']),"01",sep="-")
strptime(timelst,format="%Y-%m-%d")

Jim



On Tue, Mar 6, 2018 at 10:28 AM,   wrote:
> Hi List,
>
> The following code returns an "Error in as.POSIXlt.character(x, tz, ...) :   
> character string is not in a standard unambiguous format"
>
> require(raster)
> require(rts)
> require(stringi)
> r <- raster(ncol=100, nrow=100)
> values(r) <- runif(ncell(r))
> list(ID=seq(1:24),month=rep(str_pad(1:12, pad = 0,width = 2 , 
> "left"),2),year=sort(rep(2016:2017,12)))->dt
> stack(r)->s
> r->rs
> for(i in 1:23){
> rs[]<-r[]*i
>   addLayer(s,rs)->s
> print(nlayers(s))
> }
> timelst<-paste0(unlist(dt['year']),'-',unlist(dt['month']))
> rts(s,time=as.yearmon(timelst))->rsts
> str(rsts@time)
> apply.monthly(rsts,mean)
>
> I was expecting that the statistics accept the yearmonth format of the 
> timeslot, as it allows subsetting.
> Any suggestions?
> Thanks
> Herry
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] raster time series statistics

2018-03-05 Thread Jim Lemon
I can't test that at the moment as I don't have the libraries. Perhaps later.

Jim

On Tue, Mar 6, 2018 at 11:36 AM,   wrote:
> Last line in the following (updated) code produces the error
> require(raster)
> require(rts)
> require(stringr)
> r <- raster(ncol=100, nrow=100)
> values(r) <- runif(ncell(r))
> stack(r)->s
> r->rs
> for(i in 1:23){
>  rs[]<-r[]*i
>   addLayer(s,rs)->s
>  print(nlayers(s))
> }
> dt<-list(ID=seq(1:24),month=rep(formatC(1:12,flag=0,width=2),2),
>  year=sort(rep(2016:2017,12)))
>  timelst<-paste0(unlist(dt['year']),'-',unlist(dt['month']),"-01")
> strptime(timelst,format="%Y-%m-%d")->t1
>
> rts(s,time=as.yearmon(t1))->rsts
> subset(rsts,'2017')->r2017
> class(r2017@time)
> class(rsts@time)
>
> apply.monthly(rsts,mean)
>
>
>
> -Original Message-
> From: David Winsemius [mailto:dwinsem...@comcast.net]
> Sent: Tuesday, 6 March 2018 11:10 AM
> To: Herr, Alexander (L&W, Black Mountain) 
> Cc: r-help@r-project.org
> Subject: Re: [R] raster time series statistics
>
>
>> On Mar 5, 2018, at 3:28 PM,  
>>  wrote:
>>
>> Hi List,
>>
>> The following code returns an "Error in as.POSIXlt.character(x, tz, ...) :   
>> character string is not in a standard unambiguous format"
>
> I'm unable to produce that error. Which function was being evaluated to 
> produce the error? I don't see where as.POSIXlt would have been called. You 
> don't have any Date or POSIXt-classed variables. (I did need to also load the 
> stringr package to get str_pad into my workspace.)
>
>>
>> require(raster)
>> require(rts)
>> require(stringi)
>> r <- raster(ncol=100, nrow=100)
>> values(r) <- runif(ncell(r))
>> list(ID=seq(1:24),month=rep(str_pad(1:12, pad = 0,width = 2 ,
>> "left"),2),year=sort(rep(2016:2017,12)))->dt
>> stack(r)->s
>> r->rs
>> for(i in 1:23){
>> rs[]<-r[]*i
>>  addLayer(s,rs)->s
>> print(nlayers(s))
>> }
>> timelst<-paste0(unlist(dt['year']),'-',unlist(dt['month']))
>> rts(s,time=as.yearmon(timelst))->rsts
>> str(rsts@time)
>> apply.monthly(rsts,mean)
>>
>> I was expecting that the statistics accept the yearmonth format of the 
>> timeslot, as it allows subsetting.
>> Any suggestions?
>> Thanks
>> Herry
>>
>>   [[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.
>
> David Winsemius
> Alameda, CA, USA
>
> 'Any technology distinguishable from magic is insufficiently advanced.'   
> -Gehm's Corollary to Clarke's Third Law
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] couple of how-to-do it in R questions regarding corelations and mean and SD of likert items

2018-03-06 Thread Jim Lemon
Hi Faiz,
Just to add to the confusion:

library(prettyR)
describe(iris)

You can specify which summary measures you want in the "num.desc" argument.

Jim

On Tue, Mar 6, 2018 at 11:03 PM, faiz rasool  wrote:
> Dear list, I have the following how-to-do it in R, questions.
>
> Suppose I have ten independent variables, and one dependent variable.
> I want to find the Pearson correlation of all the IVs with the DV, but
> not the correlation between the IVs.
>
> What I know so far, about R, that I have to type the cor () function
> ten times, each time requesting for a correlation between one IV and
> the DV.
>
> I was wondering that is there a way that I can accomplish what I want
> with a single function or a fewer line of codes.
>
> My final goal is to create a table in Microsoft word comprising of ten
> rows, each row for each independent variable and its correlation with
> the DV.
>
> Based on what I know, I’ll be typing cor (IV,,DV), ten times, and then
> typing the values in the table in MS  Word.
>
>
> Secondly, I  would like to create a table that provides the details of
> means and standard deviations, of multiple variables.
>
> The variables are  ratings scores of  likert  type items. What I’d
> like to do is to construct a table, where each row has the question,
> its mean and standard deviation. I know that using the psych package,
> I can have the mean of each item in the scale, but, how to develop a
> table that has the item, mean, and SD on a same row? I do not know.
>
> Thank you for reading my questions.
>
> Regards,
> Faiz.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Empirical density estimation

2018-03-11 Thread Jim Lemon
Hi Christofer,
You may be looking for ecdf (stats) for a start, then working out a
way to translate the cumulative density values into probability
values.

Jim


On Mon, Mar 12, 2018 at 5:45 AM, Christofer Bogaso
 wrote:
> Hi,
>
> Let say I have below vector of data-points :
>
> Dat = c(-0.444, -0.25, -0.237449799196787, -0.227467046669042,
>
> -0.227454464682363, -0.22, -0.214876033057851, -0.211781206171108,
>
> -0.199891067538126, -0.192920353982301, -0.192307692307692, 
> -0.186046511627907,
>
> -0.184418145956608, -0.181818181818182, -0.181818181818182, 
> -0.181266261925412,
>
> -0.181003118503119, -0.179064587973274, -0.178217821782178, -0.17809021675454,
>
> -0.177685950413223, -0.177570093457944, -0.176470588235294, 
> -0.176470588235294,
>
> -0.174825741611282, -0.168021680216802, -0.167, 
> -0.167,
>
> -0.166380789022298, -0.164209115281501, -0.164011246485473, 
> -0.162689804772234,
>
> -0.162361623616236, -0.160161507402423, -0.16, -0.155038759689922,
>
> -0.154172560113154, -0.15311004784689, -0.151515151515152, -0.151462994836489,
>
> -0.151098901098901, -0.150537634408602, -0.150442477876106, 
> -0.150406504065041,
>
> -0.149904214559387, -0.149882903981265, -0.149797570850202, 
> -0.148496240601504,
>
> -0.148325358851675, -0.147540983606557, -0.147239263803681, 
> -0.146989966555184,
>
> -0.14622641509434, -0.146095717884131, -0.145994832041344, -0.14572864321608,
>
> -0.145161290322581, -0.144292237442922, -0.144144144144144, 
> -0.144021739130435,
>
> -0.14375, -0.142212189616253, -0.141122913505311, -0.140324963072378,
>
> -0.139344262295082, -0.13884007029877, -0.138356164383562, -0.137626262626263,
>
> -0.137142857142857, -0.136690647482014, -0.136577708006279, 
> -0.136363636363636,
>
> -0.136094674556213, -0.135879774577332, -0.135586319218241, 
> -0.135135135135135,
>
> -0.132780082987552, -0.132209405501331, -0.132023755139333, 
> -0.131233595800525,
>
> -0.130434782608696, -0.130434782608696, -0.130268199233717, 
> -0.128813559322034,
>
> -0.1284046692607, -0.128205128205128, -0.128182616330114, -0.127937336814621,
>
> -0.126283367556468, -0.125853658536585, -0.125448028673835, 
> -0.125425564840607,
>
> -0.125311203319502, -0.125, -0.124401913875598, -0.124248496993988,
>
> -0.124031007751938, -0.123572170301142, -0.123188405797102, 
> -0.122905027932961,
>
> -0.1216667, -0.121573685907772, -0.120658135283364, 
> -0.120540019286403,
>
> -0.119858156028369, -0.11965811965812, -0.11965811965812, -0.119565217391304,
>
> -0.118942731277533, -0.117820324005891, -0.116257947320618, 
> -0.115789473684211,
>
> -0.115683584819387, -0.115384615384615, -0.115281501340483, 
> -0.114492753623188,
>
> -0.114357262103506, -0.114285714285714, -0.114035087719298, 
> -0.113181972212809,
>
> -0.112790697674419, -0.112781954887218, -0.112195121951219, 
> -0.112191473448018,
>
> -0.111, -0.111, -0.110813226094727, 
> -0.110384300899428,
>
> -0.110147441457069, -0.110137672090113, -0.109913793103448, 
> -0.109792284866469,
>
> -0.109375, -0.10919540229885, -0.109112709832134, -0.10844250363901,
>
> -0.107776617954071, -0.10752688172043, -0.107317073170732, -0.106674272675414,
>
> -0.106382978723404, -0.106100795755968, -0.106060606060606, -0.10595160235448,
>
> -0.105742474070326, -0.105263157894737, -0.104454685099846, 
> -0.104283054003724,
>
> -0.103916449086162, -0.103723404255319, -0.103448275862069, 
> -0.102737680438029,
>
> -0.10267471958585, -0.101696871753434, -0.100893997445721, -0.10041265474553,
>
> -0.100042983021706, -0.1, -0.0995111731843576, -0.099502487562189,
>
> -0.0994117647058824, -0.0991561181434598, -0.0989492119089317,
>
> -0.0988372093023255, -0.0983908045977012, -0.0983050847457627,
>
> -0.0977198697068404, -0.0974702380952382, -0.0973819695475956,
>
> -0.097345132743363, -0.0971472629144179, -0.0971438645980254,
>
> -0.0961538461538461, -0.096062667491239, -0.0957347238935687,
>
> -0.0956521739130435, -0.0954773869346733, -0.0954115076474873,
>
> -0.0952380952380952, -0.0951115834218915, -0.0950642007303569,
>
> -0.0949423247559894, -0.0947368421052631, -0.0946291560102303,
>
> -0.0945220193340494, -0.0944309927360775, -0.0943016759776536,
>
> -0.0942720763723149, -0.0941770647653002, -0.0940298507462686,
>
> -0.094017094017094, -0.0935672514619884, -0.0934579439252337,
>
> -0.0930232558139535, -0.0929772502472798, -0.0929054054054054,
>
> -0.0928778745255637, -0.0927700348432055, -0.0925266903914591,
>
> -0.0922502666192677, -0.0918094218415418, -0.0915254237288135,
>
> -0.0914774596906876, -0.0914662894860915, -0.0914285714285715,
>
> -0.0912322274881517, -0.090909090909091, -0.0909090909090909,
>
> -0.09079754601227, -0.0907071455016661, -0.0906593406593406,
>
> -0.0903614457831325, -0.0903323548906352, -0.09, -0.0897243107769424,
>
> -0.0896358543417368, -0.0895522388059702, -0.0895052902487847,
>
> -0.0891719745222929, -0.0888, -0.0887227819304518,
>
> -0.0887096774193548, -0.088695652173

Re: [R] subsetting comparison problem

2018-03-11 Thread Jim Lemon
Hi Neha,
This might help:

R<-read.table(text="C1 C2 C3 C4
R1 0 1 0 1
R2 1 0 1 1
R3 1 0 0 0",
header=TRUE)
U<-read.table(text="C1 C2 C3 C4
U1 1 1 0 1
U2 1 1 1 1",
header=TRUE)
# these are matrices - I think this will work for dataframes as well
for(ui in 1:dim(U)[1]) {
 for(ri in 1:dim(R)[1]) {
  if(sum(U[ui,]&R[ri,])==sum(R[ri,]))
   cat("R$",rownames(R)[ri]," subset of ","U$",rownames(U)[ui],"\n",sep="")
 }
}

Jim

On Mon, Mar 12, 2018 at 1:59 PM, David Winsemius  wrote:
>
>> On Mar 11, 2018, at 3:32 PM, Neha Aggarwal  
>> wrote:
>>
>> Hello All,
>> I am facing a unique problem and am unable to find any help in R help pages
>> or online. I will appreciate your help for the following problem:
>> I have 2 data-frames, samples below and there is an expected output
>>
>> R Dataframe1:
>>C1  C2   C3 C4.. CN
>> R1   0  1   0   1
>> R21  0  11
>> R31  0   0 0
>> .
>> .
>> .
>> RN
>>
>> U Dataframe2 :
>> C1 C2C3 C4.. CN
>> U1 1   101
>> U2 1   1 11
>>
>>
>> Expected Output:
>> U1 satisfies R1, R3
>> U2 satisfies R1, R2, R3
>>
>
> I don't think you have communicated what sort of meaning is attached to the 
> word "satisfies".
>
> Here's a double loop that reports membership of the column names of each row 
> of U (Dataframe2) in each row of R (Dataframe1):
>
>  apply( Dataframe2, 1, function(x){ z <- which(x==1);
>z2 <- names(x)[z];
> zlist=apply(Dataframe1, 1, function(y){ z3 <- 
> which(y==1);
> z4 <- 
> names(y)[z3];
> z4[ which(z4 
> %in% z2) ]});
> zlist})
> $U1
> $U1$R1
> [1] "C2" "C4"
>
> $U1$R2
> [1] "C1" "C4"
>
> $U1$R3
> [1] "C1"
>
>
> $U2
> $U2$R1
> [1] "C2" "C4"
>
> $U2$R2
> [1] "C1" "C3" "C4"
>
> $U2$R3
> [1] "C1"
>
> --
> David.
>
>
>> So this is a comparison of dataframes problem, with a subset dimension.
>> There are 2 dataframe R and U. column names are same. There are certain
>> columns belonging to each row in dataframe 1, denoted as 1s, while there
>> are certain cols to each U denoted as 1s in each URow in dataframe2.
>>
>> I have to find relationships between Rs and Us. So i start with each U row
>> in U dataframe (lets say U1 row) and try to find all the rows in R
>> dataframe, which are subset of U1 row.
>>
>> I cant find a way to compare rows to see if one is subset of
>> anotherwhat can I try, any pointers/ packages will be great help.
>> Please help.
>>
>> Thanks
>> Neha
>>
>>   [[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.
>
> David Winsemius
> Alameda, CA, USA
>
> 'Any technology distinguishable from magic is insufficiently advanced.'   
> -Gehm's Corollary to Clarke's Third Law
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Struggling to compute marginal effects !

2018-03-19 Thread Jim Lemon
Hi Willy,
The error message may be due to passing an inappropriate environment.
I don't have the "erer" package, but if that function has a default
for the environment argument, perhaps passing just the "predvars" and
"data" arguments will work.

Jim

On Tue, Mar 20, 2018 at 8:24 AM, Willy Byamungu  wrote:
> Dear Oscar,
> and any other R-project person,
>
> Can you please help me to figure out the meaning of the following error
> message in red ?
>
> Error in eval(predvars, data, env) :
>   numeric 'envir' arg not of length one
>
> I computed ordered logit models using 'polr' in R (I just followed the
> guidance a handout I found on princeton.edu about logit, probit and
> multinomial logit models) . The summary results are obtained without any
> problem. *However*, when I'm using the package 'erer' to compute the
> marginal effects for the ordered logit models, I'm just getting the error
> message above.
>
> Please HELP 
>
> Willy
>
>
> --
> Willy Mulimbi B.
> AEAB Grad Student & Fulbright Scholar
> Tel. (+1) 479-316-5981
> Fayetteville, AR
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Struggling to compute marginal effects !

2018-03-19 Thread Jim Lemon
In that case, I can't work out why the first model fails but not the
second. I would start looking at "Data" to see what it contains. if:

object2 <- polr(Inc ~ Training ,Data,Hess = T,method = "logistic" )

works, the problem may be with the "Adopt" variable.

Jim


On Tue, Mar 20, 2018 at 10:55 AM, Willy Byamungu
 wrote:
> Sorry, do not read "Inc_reliable_fromNTA" I did a mistake in the email I
> sent you. It should be just "Inc".
>
> The situation looks like this
>
> Data$Inc <- ordered(Data$Inc =
> c("Not_reliable_at_all","Less_reliable","Somehow_reliable","Very reliable"))
>
> First model
> object1 <- polr(Inc ~ Adopt ,Data,Hess = T,method = "logistic")
>
> Marginal effect for object1:
> ocME(object1)
> Error in eval(predvars, data, env) :
>   numeric 'envir' arg not of length one
>
> Second model
> object2 <- polr(Inc ~ Adopt + Training ,Data,Hess = T,method = "logistic" )
>
> Marginal effect for object2:
> ocME(object2)
> effect.Not_reliable_at_all effect.Less_reliable effect.Somehow_reliable
> effect.Very reliable
> Adopt       -0.073   -0.057
> -0.0640.193
> Training-0.283   -0.135
> -0.0510.469
>
>
> On Mon, Mar 19, 2018 at 6:46 PM, Jim Lemon  wrote:
>>
>> Hi Willy,
>> I had a look at the "erer" manual, and it looks like a (somewhat)
>> misleading error message. I don't know where "Inc_reliable_fromNTA"
>> may be, but it looks like the ocME function can't find it, which leads
>> to the "environment" error message. You have defined "Inc" as an
>> element of "Data" and when that is used in the model, the ocME
>> function works. I suspect that  "Inc_reliable_fromNTA" is not an
>> element of "Data" and this is why ocME cannot find it.
>>
>> Jim
>>
>>
>> On Tue, Mar 20, 2018 at 10:26 AM, Willy Byamungu
>>  wrote:
>> > Dear Jim,
>> >
>> > Thank you very much for your help.
>> >
>> > My R-coding looks like this:
>> >
>> > Data$Inc <- ordered(Data$Inc =
>> > c("Not_reliable_at_all","Less_reliable","Somehow_reliable","Very
>> > reliable"))
>> >
>> > First model
>> > object1 <- polr(Inc_reliable_fromNTA ~ Adopt ,Data,Hess = T,method =
>> > "logistic")
>> >
>> > Marginal effect for object1:
>> > ocME(object1)
>> > Error in eval(predvars, data, env) :
>> >   numeric 'envir' arg not of length one
>> >
>> > Second model
>> > object2 <- polr(Inc ~ Adopt + Training ,Data,Hess = T,method =
>> > "logistic" )
>> >
>> > Marginal effect for object2:
>> > ocME(object2)
>> > effect.Not_reliable_at_all effect.Less_reliable effect.Somehow_reliable
>> > effect.Very reliable
>> > Adopt   -0.073   -0.057
>> > -0.0640.193
>> > Training-0.283   -0.135
>> > -0.0510.469
>> >>
>> >
>> > The model computing requires package "MASS" and marginal effects require
>> > "ERER". As you can see above, in the first case it succeed to provide
>> > results but in the first case NO.
>> >
>> > What do you think? By the way, what do you mean by inappropriate
>> > environment
>> > and predvars?
>> >
>> > Looking forward to hearing from you.
>> >
>> > Regards,
>> >
>> > Willy
>> >
>> > On Mon, Mar 19, 2018 at 5:33 PM, Jim Lemon  wrote:
>> >>
>> >> Hi Willy,
>> >> The error message may be due to passing an inappropriate environment.
>> >> I don't have the "erer" package, but if that function has a default
>> >> for the environment argument, perhaps passing just the "predvars" and
>> >> "data" arguments will work.
>> >>
>> >> Jim
>> >>
>> >> On Tue, Mar 20, 2018 at 8:24 AM, Willy Byamungu
>> >> 
>> >> wrote:
>> >> > Dear Oscar,
>> >> > and any other R-project person,
>> >> >
>> >> > Can you please help me to figure out the meaning of the following
>> >> > error
>> >>

Re: [R] Elements of Sets as dataframe column names

2018-03-20 Thread Jim Lemon
Hi Neha,
>From your message I think that you might get what you want with:

names(df)<-unlist(B)

However, the "sets" package might handle lists differently.

Jim

On Tue, Mar 20, 2018 at 2:24 PM, Neha Aggarwal
 wrote:
> Hello all,
>
> I have a set B and a dataframe df. I want to name the columns of the
> dataframe after the elements of the set B.
> For example, for set B with elements {{"P1"}, {"P2"}, {"P3", "P4"}} I want
> to create a new dataframe with 3  columns named {"P1"} and {"P2"} and
> {"P3","P4"}.
>
> I tried colnames(df)<-(B). But it shows the elements as list, see below:
>> colnames(df)
> [1] "list(\"P1\")" "list(\"P2\")" "list(\"P3\", \"P4\")"
>
>
> Second part of my question is what is the bests command to extract the
> elements of a set?
>
>
> Thanks,
> Neha
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] repeating functions for different folders?

2018-04-12 Thread Jim Lemon
Hi Marna,
Assuming that you are descending into different subdirectories from
the same directory:

directories<-c("dir1","dir2","dir3")
for(directory in directories) {
 setwd(directory)
 # do whatever you want to do
 # then return to the directory above
 setwd("..")
}

This will allow you to start and finish in the same directory.

Jim


On Fri, Apr 13, 2018 at 9:47 AM, Marna Wagley  wrote:
> Hi R users,
> I need to run a analysis using a data for each folder. I do have several
> folders. Each folder contains several files but these files name are
> similar to the files that is saved into  another folders.  I need to repeat
> the analysis for every folder and would like to save the output in that
> particular folder.  After completing the analysis in one folder, I want to
> move another folder. Basically I was doing manually (repeating the analysis
> each and every folder manually). Is there any way to make a loop so that I
> can run the analysis for different folders? Is there any example code?
>
> Thanks for your help.
> MW
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fwd: Help with R-Calling forth csv.

2018-04-16 Thread Jim Lemon
Hi Mohammad,
The plot you attached suggests that the underlying distribution may be
a mixture. Is there anything in your data that would explain this,
such as laden/unladen, uphill/downhill, different road surface?

Jim

On Mon, Apr 16, 2018 at 11:31 PM, Mohammad Areida  wrote:
> Hi, I do not know how to post in general again, however my csv contains
> around 5-250k data Points depending on vehicle/road type and pressure
> exerted on geotechnical structures. I have used R to develope histograms of
> said csv files and will attach such Picture to you in this mail and the csv
> used. Below I will type the R code I have used for this histogram.
>
> 
> 
>
> tryck <- read.csv("radmanso_2017.csv", sep=";", dec=",")
>
> # H??R KOLLAR VI ALLA DATA PUNKTER ##
>
> ggplot(data=tryck, aes(tryck[,1])) +
>
>   geom_histogram(aes(y =..density..),
>
>  breaks=seq(min(tryck[,1]-1), max(tryck[,1]+1), by = 0.5),
>
>  col="black",
>
>  fill="green",
>
>  alpha = .2) +
>
>   geom_density(col=2) +
>
>   labs(title="Pressure for rådmansö") +
>
>   labs(x="Pressure [kPa]", y="Amount of vehicles (Percentage)")+
>
>   stat_function(fun=dnorm, colour="blue", args = list(mean =
> mean(tryck[,1]), sd = sd(tryck[,1])))
>
>
>
> My problem now is to find a statistical distribution that corresponds well
> with my histograms with the use of Visual aids, cumulative distributions or
> goodness of fit tests which I can’t develope a code for as my csv wont get
> called forth and I do not know how to proceed from that Point on to develop
> such an aid. If you have any input on how to read the csv file and call
> forth a distribution to try on my data points such as Weibull, beta, chi or
> gen. Extreme value distributions I would much appreciate the help!
>
>
>
> Kind regards,
>
> Mohammad
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Hacked

2018-04-17 Thread Jim Lemon
It's happened 3 or 4 times for me, only on the R list. It only happens
when answering certain questions and I think all responders to that
question may get it. Seems to have nothing to do with the OP. I just
block the email address.

Jim

On Wed, Apr 18, 2018 at 1:33 PM, Mark Leeds  wrote:
> Hi All: I lately get a lot more spam-porn type emails lately also but I
> don't know if they are due to me being on
> the R-list.
>
>
>
> On Tue, Apr 17, 2018 at 5:09 PM, Rui Barradas  wrote:
>
>> Hello,
>>
>> Nor do I, no gmail, also got spam.
>>
>> Rui Barradas
>>
>> On 4/17/2018 8:34 PM, Ding, Yuan Chun wrote:
>>
>>> No, I do not use gmail, still got dirty spam email twice.
>>>
>>> -Original Message-
>>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Fowler,
>>> Mark
>>> Sent: Tuesday, April 17, 2018 12:32 PM
>>> To: Luis Puerto; Peter Langfelder
>>> Cc: R-Help ML R-Project; Neotropical bat risk assessments
>>> Subject: Re: [R] Hacked
>>>
>>> [Attention: This email came from an external source. Do not open
>>> attachments or click on links from unknown senders or unexpected emails.]
>>>
>>>
>>>
>>>
>>>
>>> Just an observation. I have not seen the spam you are discussing.
>>> Possibly it is specific to gmail addresses?
>>>
>>> -Original Message-
>>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luis
>>> Puerto
>>> Sent: April 17, 2018 4:11 PM
>>> To: Peter Langfelder
>>> Cc: R-Help ML R-Project; Neotropical bat risk assessments
>>> Subject: Re: [R] Hacked
>>>
>>> Hi!
>>>
>>> This happened to me also! I just got a spam email just after posting and
>>> then in following days I got obnoxious spam emails in my spam filter. As
>>> the others, I think that there is some kind of bot subscribed to the list,
>>> but also perhaps a spider or crawler monitoring the R-Help archive and
>>> getting email addresses there. Nabble is a possibility too.
>>>
>>> On 17 Apr 2018, at 21:50, Peter Langfelder 
 wrote:

 I got some spam emails after my last post to the list, and the emails
 did not seem to go through r-help. The spammers may be subscribed to
 the r-help, or they get the poster emails from some of the web copies
 of this list (nabble or similar).

 Peter

 On Tue, Apr 17, 2018 at 11:37 AM, Ulrik Stervbo 
 wrote:

> I asked the moderators about it. This is the reply
>
> "Other moderators have looked into this a bit and may be able to shed
> more light on it. This is a "new" tactic where the spammers appear to
> reply to the r-help post. They are not, however, going through the
> r-help server.
>
> It also seems that this does not happen to everyone.
>
> I am not sure how you can automatically block the spammers.
>
> Sorry I cannot be of more help."
>
> --Ulrik
>
> Jeff Newmiller  schrieb am Di., 17. Apr.
> 2018,
> 14:59:
>
> Likely a spammer has joined the mailing list and is auto-replying to
>> posts made to the list. Unlikely that the list itself has been
>> "hacked". Agree that it is obnoxious.
>>
>> On April 17, 2018 5:01:10 AM PDT, Neotropical bat risk assessments <
>> neotropical.b...@gmail.com> wrote:
>>
>>> Hi all,
>>>
>>> Site has been hacked?
>>> Bad SPAM arriving
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>> --
>> Sent from my phone. Please excuse my brevity.
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

 __
 R-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
>

Re: [R] Identifying columns with specific character

2018-04-18 Thread Jim Lemon
Hi Farnoosh,
Perhaps this will help:

drop_dollar<-function(x) return(as.numeric(as.character(gsub("\\$","",x
sapply(My.Data,drop_dollar)

Jim

On Thu, Apr 19, 2018 at 7:23 AM, Farnoosh Sheikhi via R-help
 wrote:
> Hello,
> I have a data frame with 400 columns and wanted to filter character columns 
> with "$" in it.For example: >  x <- c("$5", "$89", "$10", "$34")  >  y <- 
> c(1:4)>  My.Data <- data.frame (x,y)> My.Datax y1  $5 12 $89 23 $10 34 
> $34 4
> I want to detect the columns with $ and remove the $ from the selected 
> columns.I have tried apply(My.Data, 2, function (x) any(grepl("$", x))) but 
> it's not really working.Or:  apply(My.Data, 2, function(x){x<-gsub("\\$", "", 
> x)}) works but it turns all the columns to a factor.
> Thanks.
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Check if row of dataframe is superset of any row in another dataframe.

2018-04-21 Thread Jim Lemon
Hi Neha,
How about this?

find_subset<-function(x,y) {
 yrows<-dim(y)[1]
 match<-0
 for(row in 1:yrows) match<-sum(x&y[row]) >= sum(y[row])
 return(match)
}
apply(B,1,find_subset,A)

This is somewhat obscure, as the dataframe B is coerced to a matrix by
the apply function.

Jim

On Sat, Apr 21, 2018 at 5:27 PM, Neha Aggarwal
 wrote:
> Hi,
>
> I am looking for a way in which I can check if rows in 1 dataframe are
> present in another data frame in a unique way. A row in dataframe should be
> super set of any row in another dataframe.
>
> I can write a for loop for it, however, that will be inefficient. So, I am
> looking for an efficient way to do this in R.
>
> I have explained it with an example below:
>
> I want to check if a row in dataframe B is:
> 1) either equal to any row in A or
> 2) has 1's atleast for the columns where (any) row in B has 1's.
>
> My output/result is a vector of 1(TRUE) or 0(FALSE) of length equal to
> number of rows in B. The first row in B is exactly present in A so result
> has first bit as 1. Second row in B has matches with 2nd row of dataframe A
> (it has an extra 1 in 3rd column,which is ok);so second bit of result is
> also 1. Similarly, the 3rd row of B, can match to any row in A, so 3rd bit
> in result is also a 1. Next, 4th row in B has 1 for a column where no row
> in A has 1, so last bit in result is 0.
>
> Dataframe A
> 1 0 1 0
> 1 1 0 0
> 0 1 1 0
>
> Dataframe B
> 1 0 1 0
> 1 1 1 0
> 1 1 1 1
> 0 0 0 1
>
> Result<- 1 1 1 0
>
> Thanks for the help,
> Neha
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Gantt Chart Using Plotrix

2018-04-22 Thread Jim Lemon
Hi bbb_aaa,
The format for the input to the function (gantt.info) is a list. As
Sarah mentions, a data frame is a list, so as long as your columns
have the right names and are in the correct order, it should work. As
you probably know, you can import a CSV file into R as a data frame
using read.csv

Jim

On Mon, Apr 23, 2018 at 4:50 AM,   wrote:
> Hi
>
> I am trying to generate a complex Gantt chart using the gantt.chart function 
> in the plotrix package.
>
> Ideally I would like to use a spreadsheet to populate the activities (tasks) 
> and start and end dates that this function expects and then export the 
> spreadsheet file as a .CSV text file so I can read in this file to generate 
> the gantt chart. Reading through the help file I have not been able to see 
> what exactly this spreadsheet should like. The example provided with the 
> "gantt.chart" function seems to indicate all the information needs to be hand 
> coded. Because of the complexity of my chart this is not only very error 
> prone but also is impractical.
>
> Can anyone help me with this? There is also a "get.gantt.info" function for 
> creating a gantt object but the help on this is almost next to nothing !
>
> Any help you can provide on this would be great.
>
> There is another R package called "plan" which is very user friendly but for 
> my purpose this doesn't have all the functionality I am looking for.
>
> Thanks
> indr
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Overlay line on a bar plot - multiple axis

2018-04-29 Thread Jim Lemon
Hi Miluji,
You have a problem as the x-axis is different for the two plots.
However, the y-axis can be the same, so you really don't need
different axes. I think you want to display city within week. The
example below shows how to display both the counts for the cities by
week, the mean z by week and then use legends to identify the
different parts of the plot. I'm afraid that I didn't even try to do
this in ggplot.

# this uses your structure "dat"
weekcity<-dat[order(dat$week,dat$city),1:4]
barpos<-barplot(matrix(weekcity$count,nrow=5),names.arg=1:3,
 legend.text=c("Akron","Boston","Houston","NYC","OKC"),
 args.legend=list(x=8,y=6),xlab="count",
 ylab="Week",beside=TRUE,horiz=TRUE)
lines(by(weekcity$z,weekcity$week,mean),colMeans(barpos),
 type="b",lwd=2)
legend(5.5,16,"Weekly mean of z",pch=1,lty=1,lwd=2)

Jim

On Mon, Apr 30, 2018 at 4:19 AM, Miluji Sb  wrote:
> Dear all,
>
> I am trying to make a similar plot -
> https://peltiertech.com/images/2013-09/BarLineSampleChart4.png.
>
> I have data for two variables; count and z by city and week. I would like
> to have a horizontal bar plot of *count* by city and a line plot of weekly
> average of the variable *z*.
>
> I have tried the following:
>
> ggplot() + geom_bar(data=dat, aes(x=city, y=count),
> stat="identity",position="dodge") + coord_flip() +
> geom_line(data=dat, aes(x=week, y=mean_tmin))
>
> However, this flips the code for both the bar plot and the line plot. I
> would the y-axis of the line plot to be on the left-vertical axis. I read
> that it is difficult to have a secondary axis with ggplot. Any help will be
> highly appreciated. Thank you!
>
> dput(dat)
> structure(list(city = structure(c(4L, 5L, 1L, 3L, 2L, 4L, 3L,
> 1L, 2L, 5L, 3L, 1L, 2L, 4L, 5L), .Label = c("Akron", "Boston",
> "Houston", "NYC", "OKC"), class = "factor"), week = c(1L, 1L,
> 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L), count = c(2.8,
> 2.7, 3.1, 2.5, 3.5, 5.3, 4.5, 9.5, 2.7, 2.1, 4.5, 9.5, 2.7, 5.3,
> 2.1), z = c(-4.1, 1.7, 1.5, 12.8, 1.9, 4, 11.2, 1.4, 2, 4, 10.9,
> 1.4, 1.7, 3.9, 4.3), City = structure(c(4L, 5L, 1L, 3L, 2L, 4L,
> 3L, 1L, 2L, 5L, 3L, 1L, 2L, 4L, 5L), .Label = c("Akron", "Boston",
> "Houston", "NYC", "OKC"), class = "factor"), Count = c(4.47,
> 2.3, 7.37, 3.83, 2.97, 4.47, 3.83, 7.37,
> 2.97, 2.3, 3.83, 7.37, 2.97, 4.47, 2.3),
> mean_tmin = c(2.76, 2.76, 2.76, 2.76, 2.76, 4.52, 4.52, 4.52,
> 4.52, 4.52, 4.44, 4.44, 4.44, 4.44, 4.44)), .Names = c("city",
> "week", "count", "z", "City", "Count", "mean_tmin"), class = "data.frame",
> row.names = c(NA,
> -15L))
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how can I convert a long to wide matrix?

2018-05-01 Thread Jim Lemon
Hi Marna,
Try this:

library(prettyR)
stretch_df(dat,idvar="ID",to.stretch=c("EventDate","SITE"))

Jim


On Wed, May 2, 2018 at 8:24 AM, Marna Wagley  wrote:
> Hi R user,
> I was trying to convert a long matrix to wide? I have an example and would
> like to get a table (FinalData1):
>
>
> FinalData1
>  B1B2
> id_X   "A"   "B"
> id_Y   "A"   "B"
>
> but I got the following table using the following code.
>
> FinalData1
>
>  B1  B2
>
> id_X "A" "A"
>
> id_Y "A" "B"
>
>
> the code and the example data I used are given below. Is there any
> suggestions to fix the problem?
>
>
> dat<-structure(list(ID = structure(c(1L, 1L, 1L, 2L, 2L), .Label = c("id_X",
>
>
> "id_Y"), class = "factor"), EventDate = structure(c(4L, 5L, 2L,
>
> 3L, 1L), .Label = c("9/15/16", "9/15/17", "9/7/16", "9/8/16",
>
> "9/9/16"), class = "factor"), timeGroup = structure(c(1L, 1L,
>
> 2L, 1L, 2L), .Label = c("B1", "B2"), class = "factor"), SITE = structure(c(
> 1L,
>
> 1L, 2L, 1L, 2L), .Label = c("A", "B"), class = "factor")), .Names = c("ID",
>
> "EventDate", "timeGroup", "SITE"), class = "data.frame", row.names = c(NA,
>
> -5L))
>
>
> tmp <- split(dat, dat$ID)
>
> tmp1 <- do.call(rbind, lapply(tmp, function(dat){
>
> tb <- table(dat$timeGroup)
>
> idx <- which(tb>0)
>
> tb1 <- replace(tb, idx, as.character(dat$SITE))
>
> }))
>
>
> tmp1
>
> FinalData<-print(tmp1, quote=FALSE)
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how can I convert a long to wide matrix?

2018-05-01 Thread Jim Lemon
Hi Marna,
I think this is due to having three rows for id_X and only two for
id_Y. The function creates a data frame with enough columns to hold
the greatest number of values for each ID variable. Notice that the
SITE_n columns contain three values for id_X (A, A, B) and two for
id_Y (A, B, NA) as there was no third occasion of measurement for the
latter. Even though there are only two _values_ for SITE, there must
be enough space for three. In your desired output, SITE for the second
occasion of measurement is wrong (it should be "A"), and for the third
occasion it is unknown. Even if there was only one value for SITE in
the original data frame, it should be repeated for the correct number
of observations. I think you may be mixing up case ID with location of
observation.

Jim


On Wed, May 2, 2018 at 8:48 AM, Marna Wagley  wrote:
> Hi Jim,
> Thank you very much for your suggestions. I used it but it gave me three
> sites. But actually I do have only two sites "Id_X" and "Id_y" . In fact
> "A" is repeated two times for "Id_X". If it is repeated, I would like to
> take the first one among many repeated values.
>
> dat<-structure(list(ID = structure(c(1L, 1L, 1L, 2L, 2L), .Label = c("id_X",
>
> "id_Y"), class = "factor"), EventDate = structure(c(4L, 5L, 2L,
>
> 3L, 1L), .Label = c("9/15/16", "9/15/17", "9/7/16", "9/8/16",
>
> "9/9/16"), class = "factor"), timeGroup = structure(c(1L, 1L,
>
> 2L, 1L, 2L), .Label = c("B1", "B2"), class = "factor"), SITE =
> structure(c(1L,
>
> 1L, 2L, 1L, 2L), .Label = c("A", "B"), class = "factor")), .Names = c("ID",
>
> "EventDate", "timeGroup", "SITE"), class = "data.frame", row.names = c(NA,
>
> -5L))
>
> library(prettyR)
>
> stretch_df(dat,idvar="ID",to.stretch=c("EventDate","SITE"))
>
>
> ID timeGroup EventDate_1 EventDate_2 EventDate_3 SITE_1 SITE_2 SITE_3
> 1 id_XB1  9/8/16  9/9/16 9/15/17  A  A  B
> 2 id_YB1  9/7/16 9/15/16  A  B   
>>
>
> Basically I am looking for like following table
>
> ID timeGroup EventDate_1 EventDate_2 EventDate_3 SITE_1 SITE_2
> 1 id_XB1  9/8/16  9/9/16 9/15/17  A  B
> 2 id_YB1  9/7/16 9/15/16  A  B
>
> Thanks
>
>
> On Tue, May 1, 2018 at 3:32 PM, Jim Lemon  wrote:
>>
>> Hi Marna,
>> Try this:
>>
>> library(prettyR)
>> stretch_df(dat,idvar="ID",to.stretch=c("EventDate","SITE"))
>>
>> Jim
>>
>>
>> On Wed, May 2, 2018 at 8:24 AM, Marna Wagley 
>> wrote:
>> > Hi R user,
>> > I was trying to convert a long matrix to wide? I have an example and
>> > would
>> > like to get a table (FinalData1):
>> >
>> >
>> > FinalData1
>> >  B1B2
>> > id_X   "A"   "B"
>> > id_Y   "A"   "B"
>> >
>> > but I got the following table using the following code.
>> >
>> > FinalData1
>> >
>> >  B1  B2
>> >
>> > id_X "A" "A"
>> >
>> > id_Y "A" "B"
>> >
>> >
>> > the code and the example data I used are given below. Is there any
>> > suggestions to fix the problem?
>> >
>> >
>> > dat<-structure(list(ID = structure(c(1L, 1L, 1L, 2L, 2L), .Label =
>> > c("id_X",
>> >
>> >
>> > "id_Y"), class = "factor"), EventDate = structure(c(4L, 5L, 2L,
>> >
>> > 3L, 1L), .Label = c("9/15/16", "9/15/17", "9/7/16", "9/8/16",
>> >
>> > "9/9/16"), class = "factor"), timeGroup = structure(c(1L, 1L,
>> >
>> > 2L, 1L, 2L), .Label = c("B1", "B2"), class = "factor"), SITE =
>> > structure(c(
>> > 1L,
>> >
>> > 1L, 2L, 1L, 2L), .Label = c("A", "B"), class = "factor")), .Names =
>> > c("ID",
>> >
>> > "EventDate", "timeGroup", "SITE"), class = "data.frame", row.names =
>> > c(NA,
>> >
>> > -5L))
>> >
>> >
>> > tmp <- split(dat, dat$ID)
>> >
>> > tmp1 <- do.call(rbind, lapply(tmp, function(dat){
>> >
>> > tb <- table(dat$timeGroup)
>> >
>> > idx <- which(tb>0)
>> >
>> > tb1 <- replace(tb, idx, as.character(dat$SITE))
>> >
>> > }))
>> >
>> >
>> > tmp1
>> >
>> > FinalData<-print(tmp1, quote=FALSE)
>> >
>> > [[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how can I convert a long to wide matrix?

2018-05-01 Thread Jim Lemon
Hi Marna,
This is a condition that the function cannot handle. It would be
possible to reformat the result based on the time intervals, but the
stretch_df function doesn't try to interpret the values, just
stretches them out to a wide format.

Jim


On Wed, May 2, 2018 at 9:16 AM, Marna Wagley  wrote:
> Hi Jim,
> The data set is correct. I took two readings from the "SITE A" within a
> short time interval, therefore I want to take the first value if there are
> repeated within a same group of "timeGroup".
> Therefore I wanted following
>
> FinalData1
>
>  B1B2
> id_X   "A"   "B"
> id_Y   "A"   "B"
>
> thanks,
>
>
>
> On Tue, May 1, 2018 at 4:05 PM, Jim Lemon  wrote:
>>
>> Hi Marna,
>> I think this is due to having three rows for id_X and only two for
>> id_Y. The function creates a data frame with enough columns to hold
>> the greatest number of values for each ID variable. Notice that the
>> SITE_n columns contain three values for id_X (A, A, B) and two for
>> id_Y (A, B, NA) as there was no third occasion of measurement for the
>> latter. Even though there are only two _values_ for SITE, there must
>> be enough space for three. In your desired output, SITE for the second
>> occasion of measurement is wrong (it should be "A"), and for the third
>> occasion it is unknown. Even if there was only one value for SITE in
>> the original data frame, it should be repeated for the correct number
>> of observations. I think you may be mixing up case ID with location of
>> observation.
>>
>> Jim
>>
>>
>> On Wed, May 2, 2018 at 8:48 AM, Marna Wagley 
>> wrote:
>> > Hi Jim,
>> > Thank you very much for your suggestions. I used it but it gave me three
>> > sites. But actually I do have only two sites "Id_X" and "Id_y" . In fact
>> > "A" is repeated two times for "Id_X". If it is repeated, I would like to
>> > take the first one among many repeated values.
>> >
>> > dat<-structure(list(ID = structure(c(1L, 1L, 1L, 2L, 2L), .Label =
>> > c("id_X",
>> >
>> > "id_Y"), class = "factor"), EventDate = structure(c(4L, 5L, 2L,
>> >
>> > 3L, 1L), .Label = c("9/15/16", "9/15/17", "9/7/16", "9/8/16",
>> >
>> > "9/9/16"), class = "factor"), timeGroup = structure(c(1L, 1L,
>> >
>> > 2L, 1L, 2L), .Label = c("B1", "B2"), class = "factor"), SITE =
>> > structure(c(1L,
>> >
>> > 1L, 2L, 1L, 2L), .Label = c("A", "B"), class = "factor")), .Names =
>> > c("ID",
>> >
>> > "EventDate", "timeGroup", "SITE"), class = "data.frame", row.names =
>> > c(NA,
>> >
>> > -5L))
>> >
>> > library(prettyR)
>> >
>> > stretch_df(dat,idvar="ID",to.stretch=c("EventDate","SITE"))
>> >
>> >
>> > ID timeGroup EventDate_1 EventDate_2 EventDate_3 SITE_1 SITE_2 SITE_3
>> > 1 id_XB1  9/8/16  9/9/16 9/15/17  A  A
>> > B
>> > 2 id_YB1  9/7/16 9/15/16  A  B
>> > 
>> >>
>> >
>> > Basically I am looking for like following table
>> >
>> > ID timeGroup EventDate_1 EventDate_2 EventDate_3 SITE_1 SITE_2
>> > 1 id_XB1  9/8/16  9/9/16 9/15/17  A  B
>> > 2 id_YB1  9/7/16 9/15/16  A  B
>> >
>> > Thanks
>> >
>> >
>> > On Tue, May 1, 2018 at 3:32 PM, Jim Lemon  wrote:
>> >>
>> >> Hi Marna,
>> >> Try this:
>> >>
>> >> library(prettyR)
>> >> stretch_df(dat,idvar="ID",to.stretch=c("EventDate","SITE"))
>> >>
>> >> Jim
>> >>
>> >>
>> >> On Wed, May 2, 2018 at 8:24 AM, Marna Wagley 
>> >> wrote:
>> >> > Hi R user,
>> >> > I was trying to convert a long matrix to wide? I have an example and
>> >> > would
>> >> > like to get a table (FinalData1):
>> >> >
>> >> >
>> >> > FinalData1
>> >> >  B1B2
>> >> > id_X   "A"   "B"
>> >> > id_Y   "A"   &quo

Re: [R] Adding Year-Month-Day to X axis

2018-05-05 Thread Jim Lemon
Hi Greg,
What you are getting there is a factor, interpreted as a 1:n sequence
based on the sort order of your "dates". Here's a way to get dates on
your x-axis in the format you want:

x_mmdd<-as.Date(c("2018-04-25","2018-04-26","2018-04-27",
 "2018-04-28","2018-04-29","2018-04-30","2018-05-01","2018-05-02",
 "2018-05-03","2018-05-04","2018-05-05"),format="%Y-%m-%d")
plot(x_mmdd, y_duration, type="l",xaxt="n")
library(plotrix)
staxlab(1,at=x_mmdd,labels=format(x_mmdd,"%Y-%m-%d"))

Jim

On Sun, May 6, 2018 at 4:14 AM, Gregory Coats  wrote:
> I am using R 3.5.0 for Mac OS X.
> Issuing these two commands yields the expected plot.
> y_duration <- c (301.59050,  387.35700,  365.64366,  317.26150,  321.71883,  
> 342.44950,  318.95350,  322.33233,  330.60333,  428.99516,  297.82066)
> plot (y_duration, type="l”)
>
> Adding Year-Month-Day values for the x axis, and then calling plot (x,y), 
> yields a bizarre plot. Apparently, R does not understand my Year-Month-Day 
> values.
> x_mmdd <- c (2018-04-25, 2018-04-26, 2018-04-27, 2018-04-28, 2018-04-29, 
> 2018-04-30, 2018-05-01, 2018-05-02, 2018-05-03, 2018-05-04, 2018-05-05)
> plot (x_mmdd, y_duration, type="l")
>
> I would be enormously appreciative of your guidance.
> Greg Coats
> Virginia, USA
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Adding Year-Month-Day to X axis

2018-05-05 Thread Jim Lemon
Hi Greg,
The only reason I included the staxlab function in the plotrix library
was to fit all the dates onto the axis. If you want to try it:

install.packages("plotrix")

Jim


On Sun, May 6, 2018 at 9:02 AM, Gregory Coats  wrote:
> Jim, Thanks for responding!
> I am using the official R 3.5.0 for Mac OS X.
> This apparently does not include library (plotrix)
>
> library(plotrix)
> Error in library(plotrix) : there is no package called ‘plotrix’
>
> Greg
>
> On May 5, 2018, at 6:50 PM, Jim Lemon  wrote:
>
> Hi Greg,
> What you are getting there is a factor, interpreted as a 1:n sequence
> based on the sort order of your "dates". Here's a way to get dates on
> your x-axis in the format you want:
>
> x_mmdd<-as.Date(c("2018-04-25","2018-04-26","2018-04-27",
> "2018-04-28","2018-04-29","2018-04-30","2018-05-01","2018-05-02",
> "2018-05-03","2018-05-04","2018-05-05"),format="%Y-%m-%d")
> plot(x_mmdd, y_duration, type="l",xaxt="n")
> library(plotrix)
> staxlab(1,at=x_mmdd,labels=format(x_mmdd,"%Y-%m-%d"))
>
> Jim
>
>

__
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 Year-Month-Day to X axis

2018-05-06 Thread Jim Lemon
Hi Greg,
By default, the "axis" function puts the labels on one line and drops
labels that would overlap. When you have labels that are all the same
length, this usually results in every second, or third, or fourth
label being displayed. So you can probably get what you want by not
using staxlab. However, if you really want to use staxlab, try this:

oddones<-seq(1,length(x_mmdd)-1,by=2)
staxlab(1,at=x_mmdd[oddones],
 labels=format(x_mmdd,"%Y-%m-%d")[oddones])

It will also work with plain "axis", which is what you seem to want.

Jim

__
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 Year-Month-Day to X axis

2018-05-06 Thread Jim Lemon
Hi Greg,
Easy:

plot   (x_mmdd, y_duration, type="l", xaxt="n", yaxt="n",
ylim=range(240,480))
abline (h=c(240,270,300,330,360,390,420,450,480,510,540), lty=2,
lwd=1.0, col="grey40")
axis(1,at=x_mmdd,labels=format(x_mmdd,"%Y-%m-%d"))
axis(2,at=seq(240,480,by=60),labels=c("4.00","5.00","6.00","7.00","8.00"))

However, you are only getting every third label. If you want to
display more of them you can use staxlab:

staxlab(1,at=x_mmdd,labels=format(x_mmdd,"%Y-%m-%d"),nlines=3)
OR
staxlab(1,at=x_mmdd,labels=format(x_mmdd,"%Y-%m-%d"),srt=45)

Jim


On Mon, May 7, 2018 at 1:26 PM, Gregory Coats  wrote:
> Jim,
> Thank you very much!
> How do I use the axis command for side=1 to label the x horizontal axis, in
> the format="%Y-%m-%d” style?
> Greg
>
> y_duration <- c (301.59050,  387.35700,  365.64366,  317.26150,  321.71883,
> 342.44950,  318.95350,  322.33233,  330.60333,  428.99516,  297.82066,
> 258.23166)
> x_mmdd <-as.Date(c ("2018-04-25", "2018-04-26", "2018-04-27",
> "2018-04-28", "2018-04-29", "2018-04-30", "2018-05-01", "2018-05-02",
> "2018-05-03", "2018-05-04", "2018-05-05", "2018-05-06"), format="%Y-%m-%d")
> plot   (x_mmdd, y_duration, type="l", xaxt="n", yaxt="n",
> ylim=range(240,480))
> abline (h=c(240,270,300,330,360,390,420,450,480,510,540), lty=2, lwd=1.0,
> col="grey40")
> axis   (side=2, at=240,  cex.axis=1.0, label="4:00")
> axis   (side=2, at=300,  cex.axis=1.0, label="5:00")
> axis   (side=2, at=360,  cex.axis=1.0, label="6:00")
> axis   (side=2, at=420,  cex.axis=1.0, label="7:00")
> axis   (side=2, at=480,  cex.axis=1.0, label="8:00")
>
> On May 6, 2018, at 3:52 AM, Jim Lemon  wrote:
>
> Hi Greg,
> By default, the "axis" function puts the labels on one line and drops
> labels that would overlap. When you have labels that are all the same
> length, this usually results in every second, or third, or fourth
> label being displayed. So you can probably get what you want by not
> using staxlab. However, if you really want to use staxlab, try this:
>
> oddones<-seq(1,length(x_mmdd)-1,by=2)
> staxlab(1,at=x_mmdd[oddones],
> labels=format(x_mmdd,"%Y-%m-%d")[oddones])
>
> It will also work with plain "axis", which is what you seem to want.
>
> Jim
>
>

__
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 Year-Month-Day to X axis

2018-05-06 Thread Jim Lemon
Look at par(las=2) in the graphics package. You will almost certainly
have to increase the bottom margin, e.g.:

par(mar=c(6,4,4,2)

to accomodate the vertical labels.

Jim


On Mon, May 7, 2018 at 2:11 PM, Gregory Coats  wrote:
> Thanks. Regarding
> axis(1,at=x_mmdd,labels=format(x_mmdd,"%Y-%m-%d"))
>
> How do I get the text for -MM-DD to be drawn vertically, instead of
> horizontally?
> Greg
>
> On May 6, 2018, at 11:54 PM, Jim Lemon  wrote:
>
> axis(1,at=x_mmdd,labels=format(x_mmdd,"%Y-%m-%d"))
>
>

__
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 Year-Month-Day to X axis

2018-05-08 Thread Jim Lemon
Hi Greg,
This is because both plots have equally spaced x values. To see the
difference, try this:

plot (x_mmdd, y_duration, type="l", xaxt="n", yaxt="n",
ylim=range(240,480), xlab="", ylab="", col="blue")
axis(1)
plot (y_duration, type="l", xaxt="n", yaxt="n",
ylim=range(240,480), xlab="", ylab="", col="red" )
axis(1)

Jim

On Wed, May 9, 2018 at 9:00 AM, Gregory Coats  wrote:
> I do not see any difference between the x versus y plot drawn in blue, and
> the y only plot drawn in red. Is the correct?
> Greg
>
> y_duration <- c (301.59050, 387.35700, 365.64366, 317.26150, 321.71883,
> 342.44950, 318.95350, 322.33233, 330.60333, 428.99516, 297.82066, 258.23166,
> 282.01816, 280.0)
> x_mmdd <-as.Date(c ("2018-04-25", "2018-04-26", "2018-04-27",
> "2018-04-28", "2018-04-29", "2018-04-30", "2018-05-01", "2018-05-02",
> "2018-05-03", "2018-05-04", "2018-05-05", "2018-05-06", "2018-05-07",
> "2018-05-08)"), format="%Y-%m-%d")
> plot (x_mmdd, y_duration, type="l", xaxt="n", yaxt="n",
> ylim=range(240,480), xlab="", ylab="", col="blue")
> plot (y_duration, type="l", xaxt="n", yaxt="n",
> ylim=range(240,480), xlab="", ylab="", col="red" )
>

__
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] Pruning a dendrogram based on frequencies

2018-05-08 Thread Jim Lemon
Hi Franklin,
plot.dendrite was not designed to be pruned. I have had a look at the
problem, and I may be able to suggest a way to drop values in the
"dendrite" object that is the input to plot.dendrite. I'll let you
know.

Jim


On Tue, May 8, 2018 at 11:46 PM, Franklin Mairura via R-help
 wrote:
> How can one prune a dendrogram (plot.dendrite, plotrix) based on a minimum 
> level of frequencies?. Franklin.
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Seasonal weekly average

2018-05-09 Thread Jim Lemon
Hi Shakeel,
Assuming that you are starting with a bunch of dates:

# make a vector of character strings that can be converted to dates
rep_dates<-paste(sample(1:30,500,TRUE),sample(1:12,500,TRUE),
 sample(2013:2017,500,TRUE),sep="/")
# if this isn't your format, change it
date_format<-"%d/%m/%Y"
# create a data frame with a column of dates
rep_df<-data.frame(rep_dates=as.Date(rep_dates,format=date_format))
# add the week of the year
rep_df$rep_week<-format(rep_df$rep_dates,"%V")
# add the year
rep_df$rep_year<-format(rep_df$rep_dates,"%Y")
# get a table of the weekly counts by year
rep_tab<-table(rep_df$rep_week,rep_df$rep_year)
# get the row means (5 year averages)
rep5<-apply(rep_tab,1,mean)
# plot the 5 year weekly averages
plot(rep5,type="b",ylim=c(0,4),xlab="Week",ylab="Reports per week")
# add the 2017 weekly counts
points(rep_tab[,5],type="b",col="red")
legend(1,4,c("5 yr average","2017"),pch=1,lty=1,col=c("black","red"))

Jim


On Wed, May 9, 2018 at 4:37 PM, Shakeel Suleman
 wrote:
> Hi,
>
> I am fairly new to 'R' and would like advice on the following. I want to 
> calculate a weekly average number of reports (e.g. of flu, norovirus) based 
> on the same weeks for the last five years. I will then use this to plot a 
> chart with 52 points for the average based on the last five years; another 
> line will then plot the current year, enabling a comparison of current weekly 
> counts against a five  year average for the same week. I would like some 
> advice on how this can be done in 'R' . My data is disaggregated data - with 
> dates in the format in 01/01/2018.
>
> Thanks
>
> Shakeel Suleman
>
>
>
> **
> The information contained in the EMail and any attachments is confidential 
> and intended solely and for the attention and use of the named addressee(s). 
> It may not be disclosed to any other person without the express authority of 
> Public Health England, or the intended recipient, or both. If you are not the 
> intended recipient, you must not disclose, copy, distribute or retain this 
> message or any part of it. This footnote also confirms that this EMail has 
> been swept for computer viruses by Symantec.Cloud, but please re-sweep any 
> attachments before opening or saving. http://www.gov.uk/PHE
> **
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Adding Year-Month-Day to X axis

2018-05-10 Thread Jim Lemon
Hi Jayaganesh,
I'm not sure this will help, but here is a simple example using box.heresy:

y_duration <- c (16.438, 15.321, 12.700, 12.397, 10.795, 9.928, 10.386)
library(plotrix)
box.heresy(1,mean(y_duration),uinner=std.error(y_duration)
 ,ulim=sd(y_duration),intervals=TRUE)
#add the median as a circle symbol
points(1,median(y_duration))

Jim


On Wed, May 9, 2018 at 3:25 PM, Jayaganesh Anbuganapathy
 wrote:
> Helo Greg - I got it with help of your code and I would like to add the
> value into the boxplot chart. How to do that.
>
> y_duration <- c (16.438, 15.321, 12.700, 12.397, 10.795, 9.928, 10.386)
>
>
>
>
> On May 09, 2018, at 10:06 AM, Jayaganesh Anbuganapathy 
> wrote:
>
> Actually I would like to get an output on the below snapshot. I have tried
> various method like points, labels.. but nothing works. Attached is the data
> for your reference.
>
>
>
> On May 09, 2018, at 09:59 AM, Gregory Coats  wrote:
>
> I do not see any difference between the x versus y plot drawn in blue, and
> the y only plot drawn in red. Is the correct?
> Greg
>
> y_duration <- c (301.59050, 387.35700, 365.64366, 317.26150, 321.71883,
> 342.44950, 318.95350, 322.33233, 330.60333, 428.99516, 297.82066, 258.23166,
> 282.01816, 280.0)
> x_mmdd <-as.Date(c ("2018-04-25", "2018-04-26", "2018-04-27",
> "2018-04-28", "2018-04-29", "2018-04-30", "2018-05-01", "2018-05-02",
> "2018-05-03", "2018-05-04", "2018-05-05", "2018-05-06", "2018-05-07",
> "2018-05-08)"), format="%Y-%m-%d")
> plot (x_mmdd, y_duration, type="l", xaxt="n", yaxt="n",
> ylim=range(240,480), xlab="", ylab="", col="blue")
> plot ( y_duration, type="l", xaxt="n", yaxt="n", ylim=range(240,480),
> xlab="", ylab="", col="red" )
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to average values from grid cells with coordinates

2018-05-16 Thread Jim Lemon
Hi lily,
There are one or two assumptions to be made here. First is that the
latitude and longitude values of the "black" cells are equally spaced
as in your illustration. Second, that all latitude and longitude
values for the "red" cells fall at the corners of four "black" cells.

You can get the four "black" cells by finding the lat/lon values that
are closest to the "red" lat/lon values. Here's a basic example:

lat<-rep(28:38,11)
lon<-rep(98:108,each=11)
pop<-sample(80:200,121)
blackcells<-list()
for(i in 1:121) blackcells[[i]]<-list(lat=lat[i],lon=lon[i],pop=pop[i])
redcell<-list(lat=33.5,lon=100.5,pop=NA)
close4<-rep(NA,4)
closen<-1
for(i in 1:121) {
 if(abs(blackcells[[i]]$lat-redcell$lat) < 1 &&
  abs(blackcells[[i]]$lon-redcell$lon) < 1) {
  close4[closen]<-i
  closen<-closen+1
 }
}
cat(close4,"\n")
redcell$pop<-(blackcells[[close4[1]]]$pop +
 blackcells[[close4[2]]]$pop + blackcells[[close4[3]]]$pop +
 blackcells[[close4[4]]]$pop)/4
print(blackcells[[close4[1]]])
print(blackcells[[close4[2]]])
print(blackcells[[close4[3]]])
print(blackcells[[close4[4]]])
print(redcell)

As you can see, this has picked out the four "black" cells closest to
the "red" cell's coordinates and calculated the mean.

Jim

On Wed, May 16, 2018 at 2:23 PM, lily li  wrote:
> Hi R users,
>
> I have a question about data processing. I have such a dataset, while each
> black grid cell has a few attributes and the corresponding attribute
> values. The latitude and longitude of the center of each grid cell are
> given also.
>
> Then I want to average the attribute values from four adjacent grid cells
> to get the average value for the center of each red grid cell. Thus, there
> are the same number of attributes, but different values. The red grid cells
> do not overlap. I was thinking to write such a script that can ID each
> black grid cell, for example, 1, 2, 3, 4, ..., then the corresponding four
> grid cells will be used to average for the red grid cell. But I just have
> the latitude and longitude, attribute values for the black cells, and also
> latitude and longitude for the red cells, how to write such a script in R.
> Could anyone give me suggestion about the work flow? Thanks very much.
>
> I attached the picture of the grid cells here.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] exclude

2018-05-17 Thread Jim Lemon
Hi Val,
This may help:

tdat$allpresent<-FALSE
for(state in allstates)
 tdat$allpresent[tdat$stat == state]<-
  all(allyears %in% tdat$year[tdat$stat==state])
tdat2<-tdat[tdat$allpresent,]
xtabs(Y~stat+year,tdat2)
table(tdat2$stat,tdat2$year)

Jim


On Fri, May 18, 2018 at 10:48 AM, Val  wrote:
> Hi All,
>
> I have a sample of  data set show as below.
> tdat <- read.table(textConnection("stat year Y
> AL 200325
> AL 200313
> AL 200421
> AL 200620
> AL 200712
> AL 200916
> AL 201015
> FL 200663
> FL 200714
> FL 200725
> FL 200964
> FL 200947
> FL 201048
> NY 200350
> NY 200451
> NY 200657
> NY 200762
> NY 200736
> NY 200987
> NY 200996
> NY 201091
> NY 201059
> NY 201080"),header = TRUE,stringsAsFactors=FALSE)
>
> There are three states, I wan tto select states taht do ahve records in all
> year.
> Example,
> xtabs(Y~stat+year, tdat)
>  This gave me the following
>
>  stat 2003 2004 2006 2007 2009 2010
>   AL   38   21   20   12   16   15
>   FL00   63   39  111   48
>   NY   50   51   57   98  183  230
>
> Fl state does not have recrods in all year  and I wan to exclude from this
> and I want teh result   as follow
>
>  stat 2003 2004 2006 2007 2009 2010
>   AL   38   21   20   12   16   15
>   NY   50   51   57   98  183  230
>
> The other thing, how do I get teh counts state by year?
>
> Desired result,
>
>20032004   2006   2007   20092010
> AL  2   1  1   1  1 1
> NY 11 12  23
>
> 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.

__
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] Convert a list of $NULL into multiple dataframes

2018-05-18 Thread Jim Lemon
Hi Ilio,
As far as I can see, this is what you have done:

A<-data.frame(V1="Year",V2=1992,V3=1993)
B<-data.frame(V1=c("Year","18-19"),V2=c("Average (cm)",178.3),
 V3=c("N",6309),V4=c("SD",6.39))
A
V1   V2   V3
1 Year 1992 1993
B
 V1   V2   V3   V4
1  Year Average (cm)N   SD
2 18-19178.3 6309 6.39
# create "tables" from A and B
tables<-list("NULL"=A,"NULL"=B)
tables
$`NULL`
V1   V2   V3
1 Year 1992 1993

$`NULL`
 V1   V2   V3   V4
1  Year Average (cm)N   SD
2 18-19178.3 6309 6.39
# recreate A by extracting the first element of "tables"
A<-tables[[1]]
A
V1   V2   V3
1 Year 1992 1993
# recreate B by extracting the second element of "tables" minus the
fourth column
B<-tables[[2]][,-4]
B
B
V1   V2   V3
1  Year Average (cm)N
2 18-19178.3 6309

Jim

On Fri, May 18, 2018 at 6:37 PM, Ilio Fornasero
 wrote:
> I have the following list:
>
>
>
>> tables
>
>
>
> $`NULL`
>   V1 V2  V3
> 1   Year  1992  1993
>
>
>  $`NULL`
>  V1   V2 V3V4
>   1  Age Average (cm) N   SD
>   2 18-19178.3  6309 6.39
>
> I want to turn it into 2 dataframes:
>
> A
> $V1
> $V2
> $V3
>
>
> B
> $V1
> $V2
> $V3
>
>
> Any easy hint?
> Thanks
>
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to average values from grid cells with coordinates

2018-05-19 Thread Jim Lemon
Hi lily,
You could also create "blackcells" as a dataframe (which is itself a
type of list). I used a list as I thought it would be a more general
solution if there were different numbers of values for different grid
cells. The use of 1 for the comparison was due to the grid increments
being 1. If you had larger or smaller grid increments, you would use
the grid increment size for the comparison. That guarantees that only
the four nearest "black" cells will be identified as within the "red"
cell.

Jim

On Sat, May 19, 2018 at 4:07 AM, lily li  wrote:
> Hi Jim,
>
> Thanks. Yes, the two assumptions are correct, and they reflect the datasets.
> I have an uncertainty about the code below. Why do you use
> abs(blackcells[[i]]$lat - redcell$lat) <1 rather than a different number
> than 1? Second, why to construct blackcells as a list, rather than a
> dataframe. Because in a dataframe, each row can represent one grid cell,
> while the three columns can represent the lati, lon, and pop. Thanks again
> for your help.
>
> for(i in 1:121) {
> if(abs(blackcells[[i]]$lat-redcell$lat) < 1 &&
> abs(blackcells[[i]]$lon-redcell$lon) < 1) {
> close4[closen]<-i
> closen<-closen+1
> }
> }
>
> On Wed, May 16, 2018 at 2:45 AM, Jim Lemon  wrote:
>>
>> Hi lily,
>> There are one or two assumptions to be made here. First is that the
>> latitude and longitude values of the "black" cells are equally spaced
>> as in your illustration. Second, that all latitude and longitude
>> values for the "red" cells fall at the corners of four "black" cells.
>>
>> You can get the four "black" cells by finding the lat/lon values that
>> are closest to the "red" lat/lon values. Here's a basic example:
>>
>> lat<-rep(28:38,11)
>> lon<-rep(98:108,each=11)
>> pop<-sample(80:200,121)
>> blackcells<-list()
>> for(i in 1:121) blackcells[[i]]<-list(lat=lat[i],lon=lon[i],pop=pop[i])
>> redcell<-list(lat=33.5,lon=100.5,pop=NA)
>> close4<-rep(NA,4)
>> closen<-1
>> for(i in 1:121) {
>>  if(abs(blackcells[[i]]$lat-redcell$lat) < 1 &&
>>   abs(blackcells[[i]]$lon-redcell$lon) < 1) {
>>   close4[closen]<-i
>>   closen<-closen+1
>>  }
>> }
>> cat(close4,"\n")
>> redcell$pop<-(blackcells[[close4[1]]]$pop +
>>  blackcells[[close4[2]]]$pop + blackcells[[close4[3]]]$pop +
>>  blackcells[[close4[4]]]$pop)/4
>> print(blackcells[[close4[1]]])
>> print(blackcells[[close4[2]]])
>> print(blackcells[[close4[3]]])
>> print(blackcells[[close4[4]]])
>> print(redcell)
>>
>> As you can see, this has picked out the four "black" cells closest to
>> the "red" cell's coordinates and calculated the mean.
>>
>> Jim
>>
>> On Wed, May 16, 2018 at 2:23 PM, lily li  wrote:
>> > Hi R users,
>> >
>> > I have a question about data processing. I have such a dataset, while
>> > each
>> > black grid cell has a few attributes and the corresponding attribute
>> > values. The latitude and longitude of the center of each grid cell are
>> > given also.
>> >
>> > Then I want to average the attribute values from four adjacent grid
>> > cells
>> > to get the average value for the center of each red grid cell. Thus,
>> > there
>> > are the same number of attributes, but different values. The red grid
>> > cells
>> > do not overlap. I was thinking to write such a script that can ID each
>> > black grid cell, for example, 1, 2, 3, 4, ..., then the corresponding
>> > four
>> > grid cells will be used to average for the red grid cell. But I just
>> > have
>> > the latitude and longitude, attribute values for the black cells, and
>> > also
>> > latitude and longitude for the red cells, how to write such a script in
>> > R.
>> > Could anyone give me suggestion about the work flow? Thanks very much.
>> >
>> > I attached the picture of the grid cells here.
>> >
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> >
>
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to average values from grid cells with coordinates

2018-05-20 Thread Jim Lemon
Hi lily,
It's not too hard to do it using dataframes. Getting the indexing
right is usually that hardest part:

# these values are the centers of the black cells
lat<-rep(28:38,11)
lon<-rep(98:108,each=11)
pop<-sample(80:200,121)
# just use the data.frame function
blackcells<-data.frame(lat=lat,lon=lon,pop=pop)
plot(0,type="n",xlim=c(97.5,108.5),ylim=c(27.5,38.5),
 xlab="Longitude",ylab="Latitude")
abline(h=27.5)
abline(h=lat+0.5)
abline(v=97.5)
abline(v=lon+0.5)
text(blackcells$lon,blackcells$lat,pop)
# the red cells will be centered on the corners of 4 black cells
lat2<-rep(seq(28.5,34.5,by=2),4)
lon2<-rep(seq(99.5,105.5,by=2),each=4)
redcells<-data.frame(lat=lat2,lon=lon2,value=NA)
display the red cells
rect(lon2-1,lat2-1,lon2+1,lat2+1,border="red",lwd=2)
nblackcells<-dim(blackcells)[1]
nredcells<-dim(redcells)[1]
for(redcell in 1:nredcells) {
 close4<-rep(NA,4)
 closen<-1
 for(blackcell in 1:nblackcells) {
  if(abs(blackcells[blackcell,"lat"]-redcells[redcell,"lat"]) < 1 &&
   abs(blackcells[blackcell,"lon"]-redcells[redcell,"lon"]) < 1) {
   close4[closen]<-blackcells[blackcell,"pop"]
   closen<-closen + 1
  }
 }
 cat(close4,"\n")
 redcells[redcell,"value"]<-sum(close4)/4
}
library(plotrix)
boxed.labels(redcells$lon,redcells$lat,redcells$value,col="red")

Jim

__
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] Loop Function to Create Multiple Scatterplots

2018-05-21 Thread Jim Lemon
Hi Steven,
Sad to say that your CSV file didn't make it to the list and I can't
access the data via your Dropbox account. Therefore we don't know the
structure of "mydata". If you are able to plot the data as in your
example, this might help:

genexp<-matrix(runif(360,1,2),ncol=18)
colnames(genexp)<-paste("GluA.",1:18,"GRIA",1:18,"..Expression",sep="")
mydata<-cbind(Age..weeks.post.conception=20:38,genexp)
for(genecol in colnames(mydata)[2:19]) {
 png(paste0(genecol,".png"))
 plot(mydata$Age..weeks.post.conception,mydata$genecol)
}

Jim

On Mon, May 21, 2018 at 9:05 AM, STEVEN MANCINI  wrote:
> Hello,
>
> I am trying to create multiple scatter plot graphs. I have 1 independent
> variable (Age - weeks post conception) and 18 dependent variables ("Gene n"
> Expression) in one csv file. Is there a way to set up a looped function to
> produce 18 individual scatterplots? At the moment, I am writing the plot()
> function out 18 times to make the 18 graphs. My code is below and csv file
> is attached.
>
> *Code*
> wd <- setwd("~/Dropbox/Steve/SM Research Projects/Allen Brain Bank
> Project/Allen Brain Bank Inflammatory Markers Project Matlab:R/Other/2018
> Tests")
> list.files(wd)
> mydata <- read.csv("Glutamate.Genes.V1.csv")
> mydata
>
> plot(mydata$Age..weeks.post.conception., mydata$GluA1..GRIA1..Expression)
> plot(mydata$Age..weeks.post.conception.,
> mydata$GluA2..GluR2.GRIA2..Expression), etc
>
> Thank you for your time and help.
>
> Regards,
> Steven
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Plot qualitative y axis

2018-05-23 Thread Jim Lemon
Hi Pedro,
Not too hard. Just have to watch the order of the variables:

ppdf<-read.table(text="N M W
I 10 106
II 124 484
III 321 874
IV 777 1140
V 896 996
VI 1706 1250
VII 635 433
VIII 1437 654
IX 693 333
X 1343 624
XI 1221 611
XII 25 15
XIII 3 NA
XIV 7 8",
header=TRUE)
plot(rev(ppdf[,2]),1:14,col="blue",lty=1,type="l",
 yaxt="n",ylab="N",xlab="ppdf[,2]")
points(rev(ppdf[,3]),1:14,col="red",lty=1,type="l")
axis(2,at=1:14,labels=rev(ppdf[,1]))
legend(1300,14,c("M","W"),fill=c("blue","red"))
text(rev(ppdf[,2]),1:14,rev(ppdf[,2]),adj=1)
text(rev(ppdf[,3]),1:14,rev(ppdf[,3]),adj=0)

Jim


On Wed, May 23, 2018 at 7:44 AM, Pedro páramo  wrote:
>
>
> 2018-05-22 23:44 GMT+02:00 Pedro páramo :
>>
>> Many thanks,
>>
>> My goal is to make a plott like attached but the Y axis starts in XIV and
>> end at top in I.  Generally for instance in excel X axis is categories but Y
>> axis is numbers I want the contrary plotted in lines, your last help is near
>> what I look but barplot is not needed.
>>
>> Hope you can help me thanks in advance.
>>
>> 2018-05-22 0:58 GMT+02:00 Jim Lemon :
>>>
>>> Hi Pedro,
>>> In addition to the other suggestions, here's a guess at what you want
>>> by the lines for M and W:
>>>
>>> ppdf<-read.table(text="N M W
>>> I 10 106
>>> II 124 484
>>> III 321 874
>>> IV 777 1140
>>> V 896 996
>>> VI 1706 1250
>>> VII 635 433
>>> VIII 1437 654
>>> IX 693 333
>>> X 1343 624
>>> XI 1221 611
>>> XII 25 15
>>> XIII 3 NA
>>> XIV 7 8",
>>> header=TRUE)
>>> barpos<-barplot(t(as.matrix(ppdf[,2:3])),horiz=TRUE,
>>>  names.arg=ppdf$N,beside=TRUE,col=c("red","blue"))
>>> legend(1000,8,c("W","M"),fill=c("blue","red"))
>>> lines(ppdf$W,barpos[2,],col="blue")
>>> lines(ppdf$M,barpos[1,],col="red")
>>>
>>> Jim
>>>
>>>
>>> On Mon, May 21, 2018 at 10:44 PM, Pedro páramo 
>>> wrote:
>>> > Hi all,
>>> >
>>> > I´m trying to plot this data
>>> >
>>> > N M W
>>> > I 10 106
>>> > II 124 484
>>> > III 321 874
>>> > IV 777 1140
>>> > V 896 996
>>> > VI 1706 1250
>>> > VII 635 433
>>> > VIII 1437 654
>>> > IX 693 333
>>> > X 1343 624
>>> > XI 1221 611
>>> > XII 25 15
>>> > XIII 3
>>> > XIV 7 8
>>> > So that in de Y axis will be the level (qualitative data) and in the X
>>> > axis
>>> > will be M and W variables. So x axis will be wwith a lenght between 0
>>> > and
>>> > 2000.
>>> >
>>> > I would like to plot a line with M and other with W so it will be
>>> > obvious
>>> > that above V (in the Y axis) thera are more W and below level V there
>>> > are
>>> > more M.
>>> >
>>> > Can you please guide me?
>>> >
>>> > In excel putting Y as X axis is easy but dind´nt achieve to invert rows
>>> > and
>>> > I ´m trying to plot it in R.
>>> >
>>> > Many thanks in advance
>>> >
>>> > [[alternative HTML version deleted]]
>>> >
>>> > __
>>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> > https://stat.ethz.ch/mailman/listinfo/r-help
>>> > PLEASE do read the posting guide
>>> > http://www.R-project.org/posting-guide.html
>>> > and provide commented, minimal, self-contained, reproducible code.
>>
>>
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to average values from grid cells with coordinates

2018-05-23 Thread Jim Lemon
Hi lili,
You can extend it like this. I checked this with two values each for
pop and mood, and it looked okay. Obviously I didn't check the result
with 365 values for each, but it ran okay.

# these values are the centers of the black cells
lat<-rep(28:38,11)
lon<-rep(98:108,each=11)
pop<-matrix(sample(80:200,44165,replace=TRUE),ncol=365)
colnames(pop)<-paste0("pop",1:365)
mood<-matrix(sample(1:10,44165,replace=TRUE),ncol=365)
colnames(mood)<-c("mood",1:365)
# create the data frame for the black cells
blackcells<-cbind(data.frame(lat=lat,lon=lon),pop,mood)
plot(0,type="n",xlim=c(97.5,108.5),ylim=c(27.5,38.5),
 xlab="Longitude",ylab="Latitude")
abline(h=27.5)
abline(h=lat+0.5)
abline(v=97.5)
abline(v=lon+0.5)
# the red cells will be centered on the corners of 4 black cells
lat2<-rep(seq(28.5,34.5,by=2),4)
lon2<-rep(seq(99.5,105.5,by=2),each=4)
popmat<-matrix(NA,nrow=16,ncol=365)
colnames(popmat)<-paste0("pop",1:365)
moodmat<-matrix(NA,nrow=16,ncol=365)
colnames(moodmat)<-paste0("mood",1:365)
redcells<-cbind(data.frame(lat=lat2,lon=lon2),popmat,moodmat)
#display the red cells
rect(lon2-1,lat2-1,lon2+1,lat2+1,border="red",lwd=2)
nblackcells<-dim(blackcells)[1]
nredcells<-dim(redcells)[1]
for(redcell in 1:nredcells) {
 close4<-rep(NA,4)
 closen<-1
 for(blackcell in 1:nblackcells) {
  if(abs(blackcells[blackcell,"lat"]-redcells[redcell,"lat"]) < 1 &&
   abs(blackcells[blackcell,"lon"]-redcells[redcell,"lon"]) < 1) {
   close4[closen]<-blackcell
   closen<-closen + 1
  }
 }
 redcells[redcell,3:730]<-colMeans(blackcells[close4,3:730])
}

Jim

On Tue, May 22, 2018 at 1:37 PM, lily li  wrote:
> Hi Jim,
>
> Thanks. It works. I now have more complex problems. If at each blackcell,
> there are two variables such as pop and mood. For each variable, there are
> daily records in one year, so 365 records for pop and 365 records for mood.
> The averaged values for the redcells should be daily records too. What kind
> of format do you recommend for this problem? Right now, I just get the
> latitudes and longitudes into a dataframe. 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.


Re: [R] How to generate a conditional dummy in R?

2018-05-28 Thread Jim Lemon
Hi Faradj,
What a problem! I think I have worked it out, but only because the
result is the one you said you wanted.

# the sample data frame is named fkdf
Y2Xby3<-function(x) {
 nrows<-dim(x)[1]
 X<-rep(0,nrows)
 for(i in 1:(nrows-2)) {
  if(!is.na(x$Y[i])) {
   if(x$Y[i] == 1 && any(is.na(x$Y[(i+1):(i+2)]))) X[i]<-1
   if(i > 1) {
if(X[i-1] == 1) X[i]<-0
   }
  }
  else {
   if(!is.na(x$Y[i+1])) {
if(x$Y[i+1] == 1 && is.na(x$Y[i+2]) && X[i] == 0)
 X[i+1]<-1
   }
  }
 }
 return(X)
}
countries<-as.character(unique(fkdf$country))
X1<-NULL
for(country in countries)
 X1<-c(X1,Y2Xby3(fkdf[fkdf$country == country,]))
X1
  [1] 1 0 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 0
 [38] 1 0 1 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 1 0 1 0 1 0
 [75] 1 0 0 0 1 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 1 0 0
> fkdf$X
  [1] 1 0 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 0
 [38] 1 0 1 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 1 0 1 0 1 0
 [75] 1 0 0 0 1 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 1 0 0

Jim

On Mon, May 28, 2018 at 8:43 PM, Faradj Koliev  wrote:
> Hi everyone,
>
> I am trying to generate a conditional dummy variable ”X" with the following 
> rules
>
>  set X=1 if Y is =1, two years prior to the NA.  [0,0,NA].
>
> For example, if  the pattern for Y is 0,0,NA then the X variable is =0 for 
> all  the two years prior to the NA. If the pattern for Y is 0,1,NA or 1,0,NA 
> then the X =1 . To be clear, if 1,1,NA then the X=1 that  first specific 
> year, it should only count once (X=1), not twice.
>
> The code that I have now is not complete and I would appreciate some advice 
> here. This is the code:
> dat2 <- dat1 %>%
>   group_by(country) %>%
>   group_by(grp = cumsum(is.na(lag(Y))), add = TRUE) %>%
>   mutate(first_year_at_1 = match(1, Y) * any(is.na(Y)) * any(tail(Y, 3) == 
> 1L),
>  X = {x <- integer(length(Y)) ; x[first_year_at_1] <- 1L ; x}) %>%
>   ungroup()
>
> It doesn’t really generate what I described above. Any help here would be 
> much appreciated.
>
> Below you can see my sample data with the desired outcome ”X” dummy in it.
>
> Thank you!
>
>> dput(data)
> structure(list(year = c(1991L, 1992L, 1993L, 1994L, 1995L, 1996L,
> 1997L, 1998L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L,
> 2006L, 2007L, 2008L, 2009L, 2010L, 2011L, 1990L, 1991L, 1992L,
> 1993L, 1994L, 1995L, 1996L, 1997L, 1998L, 1999L, 2000L, 2001L,
> 2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L,
> 2011L, 1990L, 1991L, 1992L, 1993L, 1994L, 1995L, 1996L, 1997L,
> 1998L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L,
> 2007L, 2008L, 2009L, 2010L, 2011L, 1990L, 1991L, 1992L, 1993L,
> 1994L, 1995L, 1996L, 1997L, 1998L, 1999L, 2000L, 2001L, 2002L,
> 2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2011L,
> 1990L, 1991L, 1992L, 1993L, 1994L, 1995L, 1996L, 1997L, 1998L,
> 1999L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L,
> 2007L, 2008L, 2009L, 2010L, 2011L), country = structure(c(1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L,
> 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
> 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
> 3L, 3L, 3L, 3L, 3L, 3L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
> 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("Canada",
> "Cuba", "Dominican Republic", "Haiti", "Jamaica"), class = "factor"),
> Y = c(1L, NA, 1L, 1L, 1L, NA, 1L, NA, 1L, NA, 1L, NA, 1L,
> 1L, NA, 1L, NA, 1L, NA, 1L, NA, NA, 1L, 1L, NA, NA, 1L, NA,
> 1L, NA, 1L, NA, 1L, 1L, 1L, 1L, NA, 1L, NA, 1L, NA, 1L, NA,
> NA, 1L, NA, 1L, 0L, 0L, 0L, 1L, NA, 0L, 1L, 0L, 0L, 0L, 0L,
> 0L, 1L, NA, 0L, 1L, 1L, NA, 0L, 1L, NA, 1L, NA, 1L, NA, 1L,
> NA, 1L, NA, 1L, 1L, 1L, 1L, NA, 1L, NA, 1L, NA, 1L, NA, 1L,
> 0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, NA, 0L, 1L, 1L, 1L,
> NA, 1L, NA, 0L, 1L, 1L, NA), X = c(1L, 0L, 0L, 1L, 0L, 0L,
> 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L,
> 0L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L,
> 0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L,
> 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L,
> 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L,
> 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
> 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L)), .Names = 
> c("year",
> "country", "Y", "X"), class = "data.frame", row.names = c(NA,
> -110L))
>
>
>
> [[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.htm

Re: [R] How to generate a conditional dummy in R?

2018-05-29 Thread Jim Lemon
Hi Faradj,
Yes, the function expects at least three values for each country. Glad
it worked.

Jim


On Tue, May 29, 2018 at 10:53 PM, Faradj Koliev  wrote:
> Dear Jim,
>
> wow! It worked! Thanks a lot.
>
> I did as you suggested and it worked well with the real data. Although it
> gave me this error: Error in if (!is.na(x$Y[i])) { : argument is of length
> zero. For some reason the X1 produced less observations than it is in the
> data. But it's not a big deal - I identified those cases and simply deleted
> from the data (it was countries that only appeared twice in the data (e.g.
> USSR Yugoslavia etc).
>
> Best,
> Faradj
>
>
> 29 maj 2018 kl. 02:15 skrev Jim Lemon :
>
> Hi Faradj,
> What a problem! I think I have worked it out, but only because the
> result is the one you said you wanted.
>
> # the sample data frame is named fkdf
> Y2Xby3<-function(x) {
> nrows<-dim(x)[1]
> X<-rep(0,nrows)
> for(i in 1:(nrows-2)) {
>  if(!is.na(x$Y[i])) {
>   if(x$Y[i] == 1 && any(is.na(x$Y[(i+1):(i+2)]))) X[i]<-1
>   if(i > 1) {
>if(X[i-1] == 1) X[i]<-0
>   }
>  }
>  else {
>   if(!is.na(x$Y[i+1])) {
>if(x$Y[i+1] == 1 && is.na(x$Y[i+2]) && X[i] == 0)
> X[i+1]<-1
>   }
>  }
> }
> return(X)
> }
> countries<-as.character(unique(fkdf$country))
> X1<-NULL
> for(country in countries)
> X1<-c(X1,Y2Xby3(fkdf[fkdf$country == country,]))
> X1
>  [1] 1 0 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0
> 0
> [38] 1 0 1 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 1 0 1 0 1
> 0
> [75] 1 0 0 0 1 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 1 0 0
>
> fkdf$X
>
>  [1] 1 0 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0
> 0
> [38] 1 0 1 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 1 0 1 0 1
> 0
> [75] 1 0 0 0 1 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 1 0 0
>
> Jim
>
> On Mon, May 28, 2018 at 8:43 PM, Faradj Koliev  wrote:
>
> Hi everyone,
>
> I am trying to generate a conditional dummy variable ”X" with the following
> rules
>
> set X=1 if Y is =1, two years prior to the NA.  [0,0,NA].
>
> For example, if  the pattern for Y is 0,0,NA then the X variable is =0 for
> all  the two years prior to the NA. If the pattern for Y is 0,1,NA or 1,0,NA
> then the X =1 . To be clear, if 1,1,NA then the X=1 that  first specific
> year, it should only count once (X=1), not twice.
>
> The code that I have now is not complete and I would appreciate some advice
> here. This is the code:
> dat2 <- dat1 %>%
>  group_by(country) %>%
>  group_by(grp = cumsum(is.na(lag(Y))), add = TRUE) %>%
>  mutate(first_year_at_1 = match(1, Y) * any(is.na(Y)) * any(tail(Y, 3) ==
> 1L),
> X = {x <- integer(length(Y)) ; x[first_year_at_1] <- 1L ; x}) %>%
>  ungroup()
>
> It doesn’t really generate what I described above. Any help here would be
> much appreciated.
>
> Below you can see my sample data with the desired outcome ”X” dummy in it.
>
> Thank you!
>
> dput(data)
>
> structure(list(year = c(1991L, 1992L, 1993L, 1994L, 1995L, 1996L,
> 1997L, 1998L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L,
> 2006L, 2007L, 2008L, 2009L, 2010L, 2011L, 1990L, 1991L, 1992L,
> 1993L, 1994L, 1995L, 1996L, 1997L, 1998L, 1999L, 2000L, 2001L,
> 2002L, 2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L,
> 2011L, 1990L, 1991L, 1992L, 1993L, 1994L, 1995L, 1996L, 1997L,
> 1998L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L,
> 2007L, 2008L, 2009L, 2010L, 2011L, 1990L, 1991L, 1992L, 1993L,
> 1994L, 1995L, 1996L, 1997L, 1998L, 1999L, 2000L, 2001L, 2002L,
> 2003L, 2004L, 2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2011L,
> 1990L, 1991L, 1992L, 1993L, 1994L, 1995L, 1996L, 1997L, 1998L,
> 1999L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L, 2005L, 2006L,
> 2007L, 2008L, 2009L, 2010L, 2011L), country = structure(c(1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L,
> 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
> 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
> 3L, 3L, 3L, 3L, 3L, 3L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
> 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("Canada",
> "Cuba", "Dominican Republic", "Haiti", "Jamaica"), class = "factor"),
>Y = c(1L, NA, 1L, 1L, 1L, NA, 1L, NA, 1L, NA, 1L, NA, 1L,
>1L, NA, 1L, NA, 1L, NA, 1L, NA, NA, 1L, 1L, NA, NA, 1L, NA,
>1L, NA

Re: [R] mysterious rounding digits output

2018-05-30 Thread Jim Lemon
Hi Joshua,
Because there are no values in column ddd less than 1.

itemInfo[3,"ddd"]<-0.3645372
itemInfo
aaa   bbb   ccc   dddeee
skill 1.396 6.225 0.517 5.775  2.497
predict   1.326 5.230 0.462 5.116 -2.673
waiting   1.117 4.948NA 0.365 NA
complex   1.237 4.170 0.220 4.713  5.642
novelty   1.054 4.005 0.442 4.260  2.076
creative  1.031 3.561 0.362 3.689  2.549
evaluated 0.963 3.013NANA NA
body  0.748 2.238 0.596 2.019  0.466
control   0.620 2.149NANA NA
stakes0.541 1.905 0.227 2.020  2.343
spont 0.496 1.620NANA NA
chatter   0.460 1.563 0.361 1.382  0.540
present   0.428 1.236 0.215 1.804  2.194
reward0.402 1.101 0.288 1.208  0.890
feedback  0.283 0.662NANA NA
goal  0.237 0.474NANA NA

digits specifies the number of significant digits ("It is a suggestion
only"), so when at least one number is padded with a leading zero it
affects the formatting of the other numbers in that column. I suspect
that this is an esthetic consideration to line up the decimal points.

Jim


On Thu, May 31, 2018 at 11:18 AM, Joshua N Pritikin  wrote:
> R version 3.5.0 (2018-04-23) -- "Joy in Playing"
> Platform: x86_64-pc-linux-gnu (64-bit)
>
> options(digits=3)
>
> itemInfo <- structure(list("aaa" = c(1.39633732316667, 1.32598263816667,  
> 1.1165832407, 1.23651072616667, 1.0536867998, 1.0310073738,  
> 0.9630728395, 0.7483865045, 0.62008664617, 0.5411017985,  
> 0.49639760783, 0.45952804467, 0.42787704783, 0.40208597967,  
> 0.28316118123, 0.23689627723), "bbb" = c(6.22533860696667,  
> 5.229736804, 4.94816041772833, 4.17020503255333, 4.00453781427167,  
> 3.56058007398333, 3.0125202404, 2.2378235873, 2.14863910661167,  
> 1.90460903044777, 1.62001089796667, 1.56341257968151, 1.23618558850667,  
> 1.10086688908262, 0.661981500639833, 0.47397754310745), "ccc" = 
> c(0.5165911355,  0.46220470767, NA, 0.21963592433, 0.44186378083, 
>  0.36150286583, NA, 0.59613794667, NA, 0.22698477157,  NA, 
> 0.36092266158, 0.2145347068, 0.28775624948, NA, NA ), "ddd" = 
> c(5.77538400186667,  5.115877113, NA, 4.71294520316667, 4.25952652129833, 
> 3.68879921863167,  NA, 2.01942456211145, NA, 2.02032557108, NA, 1.381810875
 9571,  1.80436759778167, 1.20789851993367, NA, NA), "eee" = 
c(2.4972534717,  -2.67340172316667, NA, 5.6419520633, 2.0763355523, 
2.548949539,  NA, 0.465537272243167, NA, 2.34255027516667, NA, 0.5400824922975, 
 2.1935000655, 0.89000797687, NA, NA)), row.names = c("skill",  "predict", 
"waiting", "complex", "novelty", "creative", "evaluated",  "body", "control", 
"stakes", "spont", "chatter", "present", "reward",  "feedback", "goal"), class 
= "data.frame")
>
> itemInfo  # examine column ddd
>
> When I try this, column ddd has 1 fewer digits than expected. See the
> attached screenshot.
>
> Why don't all the columns have the same number of digits displayed?
>
> --
> Joshua N. Pritikin, Ph.D.
> Virginia Institute for Psychiatric and Behavioral Genetics
> Virginia Commonwealth University
> PO Box 980126
> 800 E Leigh St, Biotech One, Suite 1-133
> Richmond, VA 23219
> http://exuberant-island.surge.sh
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Plot in real unit (1:1)

2018-06-06 Thread Jim Lemon
Hi Christian,
When I have to do something like this, I usually write it in
Postscript using this:

/def mm 2.8346 mul

that converts a dimension in mm to points (1/72 inch). However, this
won't work in R. It may be possible to set up the device like this:

postscript("myfile.ps",paper="a4")
par(mar=c(0,0,0,0))
# generate a blank plot
plot(0,type="n",xlim=c(0,210),ylim=c(0,297),axes=FALSE)
# display lines, etc. in mm with 0,0 at the bottom left
dev.off()

The resulting file should be printable. Warning, I don't have time to
test this right now.

Jim



On Thu, Jun 7, 2018 at 12:00 AM, Christian Brandstätter
 wrote:
> Dear List,
>
> Is it possible to plot in R in "real" units? I would like to draw a
> plot on A4 paper, where 1 plot unit would be a mm in reality. Is
> something like that possible? I would also like to be able to scale the
> plot in x and y direction.
> Background: For a project I would have to draw around 65 fast sketches
> of elevation courves.
>
> Copied from here, due to no answer: https://stackoverflow.com/questions
> /50606797/plot-in-real-units-mm
>
> Thank you!
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Plot in real unit (1:1)

2018-06-06 Thread Jim Lemon
Hi Christian,
Well, it almost worked. I suspect that the postscript device adds some
padding to account for the printable area, so with a bit of
experimentation, The following example seems to do what you want. When
I printed the resulting file from the GIMP, the box and diamond were
the correct dimensions.

postscript("test.ps",paper="a4",horizontal=FALSE)
par(mai=c(1.713,0,1.713,0),xaxs="i",yaxs="i")
plot(0,type="n",xlim=c(0,190),ylim=c(0,190),xlab="",axes=FALSE)
segments(c(0,95),c(95,0),c(190,95),c(95,190))
segments(c(45,95,145,95),c(95,145,95,45),
 c(95,145,95,45),c(145,95,45,95))
box()
dev.off()

Jim

On Thu, Jun 7, 2018 at 8:16 AM, Jim Lemon  wrote:
> Hi Christian,
> When I have to do something like this, I usually write it in
> Postscript using this:
>
> /def mm 2.8346 mul
>
> that converts a dimension in mm to points (1/72 inch). However, this
> won't work in R. It may be possible to set up the device like this:
>
> postscript("myfile.ps",paper="a4")
> par(mar=c(0,0,0,0))
> # generate a blank plot
> plot(0,type="n",xlim=c(0,210),ylim=c(0,297),axes=FALSE)
> # display lines, etc. in mm with 0,0 at the bottom left
> dev.off()
>
> The resulting file should be printable. Warning, I don't have time to
> test this right now.
>
> Jim
>
>
>
> On Thu, Jun 7, 2018 at 12:00 AM, Christian Brandstätter
>  wrote:
>> Dear List,
>>
>> Is it possible to plot in R in "real" units? I would like to draw a
>> plot on A4 paper, where 1 plot unit would be a mm in reality. Is
>> something like that possible? I would also like to be able to scale the
>> plot in x and y direction.
>> Background: For a project I would have to draw around 65 fast sketches
>> of elevation courves.
>>
>> Copied from here, due to no answer: https://stackoverflow.com/questions
>> /50606797/plot-in-real-units-mm
>>
>> Thank you!
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Changing selected columns to factor

2018-06-11 Thread Jim Lemon
Hi Jeff,

jrdf<-data.frame(A=rnorm(10),B=rnorm(10),C=rnorm(10),
 D=rnorm(10),E=rnorm(10),F=rnorm(10),G=rnorm(10),
 H=rnorm(10),I=rnorm(10),J=rnorm(10))
for(i in c(2,7,8,9)) jrdf[,i]<-factor(jrdf[,i])
sapply(jrdf,"class")

Jim

On Tue, Jun 12, 2018 at 9:57 AM, Jeff Reichman  wrote:
> R-Help Forum
>
>
>
> If I have a data frame consisting of say ten (10) variables
> (A,B,C,D,E,F,G,H,I,J) and I want to change Variables 2,7,8,and 9 to factors
> is there a command such that I can do it in one line or do I simply have to
> convert each separately?
>
>
>
> Jeff
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Data frame with Factor column missing data change to NA

2018-06-13 Thread Jim Lemon
Hi Bill,
It may be that the NonAcceptanceOther, being a character value, has ""
(0 length string) rather than NA. You can convert that to NA like
this:

df2$NonAcceptanceOther[nchar(df2$NonAcceptanceOther) == 0]<-NA

Jim


On Thu, Jun 14, 2018 at 12:47 AM, Bill Poling  wrote:
> Good morning.
>
> #I have df with a Factor column called "NonAcceptanceOther" that contains 
> missing data.
>
> #Not every record in the df is expected to have a value in this column.
>
> # Typical values look like:
> # ERS
> # Claim paid without PHX recommended savings
> # Claim paid without PHX recommended savings
> # MRC Amount
> # MRC Amount
> # PPO per provider
> #Or they are missing (blank)
>
> #Example
>
> df2 <- 
> df[,c("PlaceOfService","ClaimStatusID","NonAcceptanceOther","RejectionCodeID","CPTCats","RevCodeCats","GCode2","ClaimTypeID")]
> head(df2, n=20)
>
>PlaceOfService ClaimStatusID NonAcceptanceOther 
> RejectionCodeID  CPTCats RevCodeCats GCode2 ClaimTypeID
>
> 1  11 2   
>   NA  ResPSys NotValidRevCode  2   2
>
> 2  81 3   
>   53   PathandLab NotValidRevCode  2   2
>
> 3  11 3   
>   47 Medicine NotValidRevCode  1   2
>
> 4  09 2   
>   NA   NotCPT NotValidRevCode  1   2
>
> 5  11 2   
>   NARadiology NotValidRevCode  2   2
>
> 6  23 2   
>   NA   MusculoSys NotValidRevCode  2   2
>
> 7  12 3   
>   47   NotCPT NotValidRevCode  2   2
>
> 8  12 2   
>   NA Medicine NotValidRevCode  2   2
>
> 9  11 3   
>   47 Medicine NotValidRevCode  1   2
>
> 10 21 2   
>   NA   Anesthesia NotValidRevCode  2   2
>
> 11 11 3ERS
>   30  EvalandMgmt NotValidRevCode  2   2
>
> 12 81 2   
>   NA   PathandLab NotValidRevCode  2   2
>
> 13 21 2   
>   NARadiology NotValidRevCode  1   2
>
> 14 11 2   
>   NA Medicine NotValidRevCode  1   2
>
> 15 99 3 Claim paid without PHX recommended savings
>   30 CardioHemLympSys Lab  0   1
>
> 16 99 3 Claim paid without PHX recommended savings
>   30   PathandLab Lab  0   1
>
> 17 99 3 MRC Amount
>   30   NotCPT  Pharma  2   1
>
> 18 99 3 MRC Amount
>   30   PathandLab Lab  2   1
>
> 19 81 2   
>   NA   PathandLab NotValidRevCode  2   2
>
> 20 23 2   
>   NA IntegSys NotValidRevCode  1   2
>
> #I would like to set these missing to NA and have them reflected similarly to 
> an NA in a numeric or integer column if possible.
>
> #I have tried several approaches from Googled references:
>
> NonAcceptanceOther <- df$NonAcceptanceOther
> table(addNA(NonAcceptanceOther))
>
> is.na <- df$NonAcceptanceOther
>
> df[NonAcceptanceOther == '' | NonAcceptanceOther == 'NA'] <- NA
>
> #However, when I go to use:
>
> missingDF <- PlotMissing(df)
>
> #Only the columns that are numeric or integer reflect their missing values 
> (i.e. RejectionCodeID)  and this "NonAcceptanceOther" column does not reflect 
> or hold the NA values?
>
> Thank you for any advice.
>
> WHP
>
>
>
>
>
>
>
>
>
>
>
>
> Confidentiality Notice This message is sent from Zelis. ...{{dropped:16}}
>
> __
> 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

Re: [R] tapply and error bars

2018-06-23 Thread Jim Lemon
Hi Ogbos,
This may help:

# assume your data frame is named "oodf"
oomean<-as.vector(by(oodf$B,oodf$A,mean))
oose<-as.vector(by(oodf$B,oodf$A,std.error))
plot(-5:10,oomean,type="b",ylim=c(5,11),
 xlab="days (epoch is the day of Fd)",ylab="strikes/km2/day")
dispersion(-5:10,oomean,oose)

Jim

On Sat, Jun 23, 2018 at 4:35 PM, Ogbos Okike  wrote:
> Dear workers,
> I have a data of length 1136. Below is the code I use to get the means B.
> It worked fine and I had the mean calculated and plotted.
>
> I wish to plot the error bars as well. I already plotted such means with
> error bars before. Please see attached for example.
>
> I tried to redo the same plot but unlikely could not get around it as I
> lost my system containing the script.
> Among many attempts, I tried:
> library(gplots)
>
>  plotmeans(errors~AB,xlab="Factor A",ylab="mean errors", p=.68, main="Main
>   effect Plot",barcol="black")
> Nothing worked.
>
> I would really be thankful should somebody return me to the track.
> Many, many thanks for your time.
> Ogbos
>
> A sample of the data is:
> S/N  AB
> 1-5  64833
> 2-4  95864
> 3-3  82322
> 4-2  95591
> 5-1  69378
> 6 0  74281
> 7 1 103261
> 8 2  92473
> 9 3  84344
> 104 127415
> 115 123826
> 126 100029
> 137  76205
> 148 105162
> 159 119533
> 16   10 106490
> 17   -5  82322
> 18   -4  95591
> 19   -3  69378
> 20   -2  74281
> 21   -1 103261
> 220  92473
> 231  84344
> 242 127415
> 253 123826
> 264 100029
> 275  76205
> 286 105162
> 297 119533
> 308 106490
> 319 114771
> 32   10  55593
> 33   -5  85694
> 34   -4  65205
> 35   -3  80995
> 36   -2  51723
> 37   -1  62310
> 380  53401
> 391  65677
> 402  76094
> 413  64035
> 424  68290
> 435  73306
> 446  82176
> 457  75566
> 468  89762
> 479  88063
> 48   10  94395
> 49   -5  80651
> 50   -4  81291
> 51   -3  63702
> 52   -2  70297
> 53   -1  64117
> 540  71219
> 551  57354
> 562  62111
> 573  42252
> 584  35454
> 595  33469
> 606  38899
> 617  64981
> 628  85694
> 639  79452
> 64   10  85216
> 65   -5  71219
> 66   -4  57354
> 67   -3  62111
> 68   -2  42252
> 69   -1  35454
> 700  33469
> 711  38899
> 722  64981
> 733  85694
> 744  79452
> 755  85216
> 766  81721
> 777  91231
> 788 107074
> 799 108103
> 80   10  7576
>
> A<-matrix(rep(-5:10,71))
> B<-matrix(data)
>  AB<-data.frame(A,B)
>
> x= B
>
>  f<-factor(A)
> AB<- tapply(x,f,mean)
> x<--5:10
> plot(x,AB,type="l")
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] tapply and error bars

2018-06-24 Thread Jim Lemon
Hi Ogbos,
If I use the example data that you sent, I get the error after this line:

oose<-as.vector(by(oodf$B,oodf$A,std.error))
Error in FUN(X[[i]], ...) : object 'std.error' not found

The reason is that you have not defined std.error as a function, but
as the result of a calculation. When I rewrite it like this:

std.error<-function(x) return(sd(x)/(sum(!is.na(x
oose<-as.vector(by(oodf$B,oodf$A,std.error))
plot(-5:10,oomean,type="b",ylim=c(5,11),
 xlab="days (epoch is the day of Fd)",ylab="strikes/km2/day")
dispersion(-5:10,oomean,oose)

I get the expected plot.

Jim


On Sat, Jun 23, 2018 at 9:36 PM, Ogbos Okike  wrote:
> Hi Jim,
>
> Thanks for assisting. Here is what I did:
>
> A<-matrix(rep(-5:10,71))
> B<-matrix(data)
> std.error = sd(B)/sqrt(sum(!is.na(B)))
>  oodf<-data.frame(A,B)
>
>  oomean<-as.vector(by(oodf$B,oodf$A,mean))
> oose<-as.vector(by(oodf$B,oodf$A,std.error))
> plot(-5:10,oomean,type="b",ylim=c(5,11),
>  xlab="days (epoch is the day of Fd)",ylab="strikes/km2/day")
> dispersion(-5:10,oomean,oose)
>
> And the error says:
> Error in FUN(X[[1L]], ...) : could not find function "FUN"
>
> Please note that I use:
> std.error = sd(B)/sqrt(sum(!is.na(B)))
>  to calculate the standard error as it requested for it.
>
> Thanks
> Ogbos
>
> On Sat, Jun 23, 2018 at 10:09 AM, Jim Lemon  wrote:
>>
>> Hi Ogbos,
>> This may help:
>>
>> # assume your data frame is named "oodf"
>> oomean<-as.vector(by(oodf$B,oodf$A,mean))
>> oose<-as.vector(by(oodf$B,oodf$A,std.error))
>> plot(-5:10,oomean,type="b",ylim=c(5,11),
>>  xlab="days (epoch is the day of Fd)",ylab="strikes/km2/day")
>> dispersion(-5:10,oomean,oose)
>>
>> Jim
>>
>> On Sat, Jun 23, 2018 at 4:35 PM, Ogbos Okike 
>> wrote:
>> > Dear workers,
>> > I have a data of length 1136. Below is the code I use to get the means
>> > B.
>> > It worked fine and I had the mean calculated and plotted.
>> >
>> > I wish to plot the error bars as well. I already plotted such means with
>> > error bars before. Please see attached for example.
>> >
>> > I tried to redo the same plot but unlikely could not get around it as I
>> > lost my system containing the script.
>> > Among many attempts, I tried:
>> > library(gplots)
>> >
>> >  plotmeans(errors~AB,xlab="Factor A",ylab="mean errors", p=.68,
>> > main="Main
>> >   effect Plot",barcol="black")
>> > Nothing worked.
>> >
>> > I would really be thankful should somebody return me to the track.
>> > Many, many thanks for your time.
>> > Ogbos
>> >
>> > A sample of the data is:
>> > S/N  AB
>> > 1-5  64833
>> > 2-4  95864
>> > 3-3  82322
>> > 4-2  95591
>> > 5-1  69378
>> > 6 0  74281
>> > 7 1 103261
>> > 8 2  92473
>> > 9 3  84344
>> > 104 127415
>> > 115 123826
>> > 126 100029
>> > 137  76205
>> > 148 105162
>> > 159 119533
>> > 16   10 106490
>> > 17   -5  82322
>> > 18   -4  95591
>> > 19   -3  69378
>> > 20   -2  74281
>> > 21   -1 103261
>> > 220  92473
>> > 231  84344
>> > 242 127415
>> > 253 123826
>> > 264 100029
>> > 275  76205
>> > 286 105162
>> > 297 119533
>> > 308 106490
>> > 319 114771
>> > 32   10  55593
>> > 33   -5  85694
>> > 34   -4  65205
>> > 35   -3  80995
>> > 36   -2  51723
>> > 37   -1  62310
>> > 380  53401
>> > 391  65677
>> > 402  76094
>> > 413  64035
>> > 424  68290
>> > 435  73306
>> > 446  82176
>> > 457  75566
>> > 468  89762
>> > 479  88063
>> > 48   10  94395
>> > 49   -5  80651
>> > 50   -4  81291
>> > 51   -3  63702
>> > 52   -2  70297
>> > 53   -1  64117
>> > 540  71219
>> > 551  57354
>> > 562  62111
>> > 573  42252
>> > 584  35454
>> > 595  33469
>> > 606  38899
>> > 617  64981
>> > 628  85694
>> > 639  79452
>> > 64   10  85216
>> > 65   -5  71219
>> > 66   -4  57354
>> > 67   -3  62111
>> > 68   -2  42252
>> > 69   -1  35454
>> > 700  33469
>> > 711  38899
>> > 722  64981
>> > 733  85694
>> > 744  79452
>> > 755  85216
>> > 766  81721
>> > 777  91231
>> > 788 107074
>> > 799 108103
>> > 80   10  7576
>> >
>> > A<-matrix(rep(-5:10,71))
>> > B<-matrix(data)
>> >  AB<-data.frame(A,B)
>> >
>> > x= B
>> >
>> >  f<-factor(A)
>> > AB<- tapply(x,f,mean)
>> > x<--5:10
>> > plot(x,AB,type="l")
>> >
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> >
>
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] tapply and error bars

2018-06-24 Thread Jim Lemon
Hi Ogbos,
The problem is almost certainly with the data. I get the plot I expect
with the sample data that you first posted, so I know that the code
works. If you try thIs what do you get?

oodf<-read.table(text="S/N  AB
1-5  64833
2-4  95864
3-3  82322
4-2  95591
5-1  69378
6 0  74281
7 1 103261
8 2  92473
9 3  84344
104 127415
115 123826
126 100029
137  76205
148 105162
159 119533
16   10 106490
17   -5  82322
18   -4  95591
19   -3  69378
20   -2  74281
21   -1 103261
220  92473
231  84344
242 127415
253 123826
264 100029
275  76205
286 105162
297 119533
308 106490
319 114771
32   10  55593
33   -5  85694
34   -4  65205
35   -3  80995
36   -2  51723
37   -1  62310
380  53401
391  65677
402  76094
413  64035
424  68290
435  73306
446  82176
457  75566
468  89762
479  88063
48   10  94395
49   -5  80651
50   -4  81291
51   -3  63702
52   -2  70297
53   -1  64117
540  71219
551  57354
562  62111
573  42252
584  35454
595  33469
606  38899
617  64981
628  85694
639  79452
64   10  85216
65   -5  71219
66   -4  57354
67   -3  62111
68   -2  42252
69   -1  35454
700  33469
711  38899
722  64981
733  85694
744  79452
755  85216
766  81721
777  91231
788 107074
799 108103
80   10  7576",
header=TRUE)
library(plotrix)
std.error<-function(x) return(sd(x)/(sum(!is.na(x
oomean<-as.vector(by(oodf$B,oodf$A,mean))
oose<-as.vector(by(oodf$B,oodf$A,std.error))
plot(-5:10,oomean,type="b",ylim=c(5,11),
 xlab="days (epoch is the day of Fd)",ylab="strikes/km2/day")
dispersion(-5:10,oomean,oose)

I get the attached plot;

Jim

On Mon, Jun 25, 2018 at 1:58 AM, Ogbos Okike  wrote:
> Hi Jim
>
> Thanks again for returning to this.
> please not that the line "oomean<-as.vector(by(oodf$B,oodf$A,mean))" was
> omitted (not sure whether deliberate)  after you introduced the standard
> error function.
> When I used it, empty plot window with the correct axes were generated but
> no data was displayed. No error too.
>
> library(plotrix)
> std.error<-function(x) return(sd(x)/(sum(!is.na(x
> oose<-as.vector(by(oodf$B,oodf$A,std.error))
> plot(-5:10,oomean,type="b",ylim=c(5,11),
>  xlab="days (epoch is the day of Fd)",ylab="strikes/km2/day")
> dispersion(-5:10,oomean,oose)
>
> When I included the line, the same empty graph window was generated but with
> the former error "Error in FUN(X[[1L]], ...) : could not find function
> "FUN""
> library(plotrix)
> std.error<-function(x) return(sd(x)/(sum(!is.na(x
> oomean<-as.vector(by(oodf$B,oodf$A,mean))
> oose<-as.vector(by(oodf$B,oodf$A,std.error))
> plot(-5:10,oomean,type="b",ylim=c(5,11),
>  xlab="days (epoch is the day of Fd)",ylab="strikes/km2/day")
> dispersion(-5:10,oomean,oose)
>
> I am sure am missing something but can't place it. Please have a look again
> to track my mistake.
>
> Warmest regards
> Ogbos
>


ooplot.pdf
Description: Adobe PDF document
__
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] Outputting variable names and their value bindings

2018-06-24 Thread Jim Lemon
Hi Simon,
Easy to do if you call "print" directly:

print<-function(x) cat(deparse(substitute(x)),"=\n",x,"\n")
y<-3
print(y)
y =
 3

Obviously you will want to get rid of your print function when it is
not being used with "rm" or by starting a new session. Getting it to
bypass the default print method is more difficult and I don't have the
time to untangle that one at the moment.

Jim

__
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 Axis value to R Plot

2018-06-25 Thread Jim Lemon
Hi Abou,
You can't display an axis if it is not in the range of the plot. I
think you want:

plot(0,type="n",yaxs="i",xaxs="i",xaxt="n",yaxt="n",xlim=c(15,85),
 ylim=c(300,600),xlab="Age",ylab="Distance (ft)",cex.lab=1.5)
grid(nx = 10, ny = 10, col = "lightgray", lty = "dotted", lwd = 2)
xticks <- c(15,25,35,45,55,65,75,85)
yticks <- c(300,400,500,600)
axis(1,at=xticks)
axis(2,at=yticks)

Note the addition of xlim and ylim arguments.

Jim

On Tue, Jun 26, 2018 at 12:36 AM, AbouEl-Makarim Aboueissa
 wrote:
> Dear All: good morning
>
>
>
> within this code, please see below,
>
>
> plot(0:1.0, 0:1.0, type = "n",  yaxs = "i", xaxs = "i", xaxt = "n", yaxt =
> "n", xlab = "Age", ylab = "Distance (ft)",  cex.lab=1.5)
> grid(nx = 10, ny = 10, col = "lightgray", lty = "dotted", lwd = 2)
>
>
>
> Is there a way to force R to add the following Axis ticks to this plot
>
>
> xticks <- c(15,25,35,45,55,65,75,85)
> yticks <- c(300,400,500,600)
>
>
>
> with many thanks
> abou
> __
>
>
> *AbouEl-Makarim Aboueissa, PhD*
>
> *Professor of Statistics*
>
> *Department of Mathematics and Statistics*
> *University of Southern Maine*
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How long can a csv file label be?

2018-06-27 Thread Jim Lemon
Hi Nick,
You are probably using Windows, for which the maximum path length is
claimed to be 260 characters. The most common alternative, Linux, has
a maximum filename length of 255 and a maximum path length of 4096. If
you are simply writing a file to the current path, it won't make much
difference.

Jim

On Thu, Jun 28, 2018 at 8:33 AM, Nick Wray via R-help
 wrote:
> Hi For various reasons too dull to go into I have been trying to write csv 
> files from R with very long filenames.  However R doesn't seem to like my 
> doing this, but it is not clear to me what the maximum filename size is, and 
> I can't find the info on the net.  I believe that the maximum pathname is 255 
> characters but is that the same thing?
>
> Thanks if anyone can enlighten me
>
> 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.

__
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] trouble with exiting loop if condition is met

2018-06-28 Thread Jim Lemon
Hi Kelly,
You seem to be testing the two "years" independently, so here is a
possible solution:

npg<-16
futility1<-futility2<-psignif1<-psignif2<-nrep<-0
while(!futility1 && !futility2 && !psignif1 && !psignif2 && nrep < 1) {
 control_respond1<-sum(runif(npg,0,1) < 0.05)
 control_respond2<-sum(runif(npg,0,1) < 0.05)
 treat_respond1<-sum(runif(npg,0,1) < 0.3)
 treat_respond2<-sum(runif(npg,0,1) < 0.3)
 futility1<-treat_respond1 == 0
 futility2<-treat_respond2 == 0
 psignif1<-fisher.test(matrix(c(control_respond1,npg-control_respond1,
  treat_respond1,npg-treat_respond1),nrow=2),
  alternative="greater")$p.value < 0.01
 psignif2<-fisher.test(matrix(c(control_respond2,npg-control_respond2,
  treat_respond2,npg-treat_respond2),nrow=2),
  alternative="greater")$p.value < 0.01
 nrep<-nrep+1
}
cat("futility1",futility1,"futility2",futility2,"psignif1",psignif1,
 "psignif2",psignif2,"nrep",nrep,"\n")

The output tells you which condition was met and on which repetition
it occurred. The outcomes for all previous repetitions will be FALSE
and for the remaining repetitions, undefined (unless you have a cat
named Schrodinger)..

If you want to test the two "years" as sequential observations, it
will only require a minor modification.

Jim

On Fri, Jun 29, 2018 at 5:53 AM, Kelly Wu  wrote:
> I am working on a clinical trial simulation with two groups, treatment and
> placebo, and the outcome is dichotomous (recovery or no recovery) . I would
> like to stop my loop if either of my conditions are met:
>
> 1) futility - there are no responses to treatment in the treatment group.
> 2) the p-value is significant (<=0.01).
>
> The problem I am having is my loop continues to run 10,000 times even though
> I am sure that at least one of the conditions are met in some instances. It
> appears the main problem is that my if loop is not adequately filtering the
> conditions I specified in it.
>
> library(magrittr)
> library(dplyr)
>
> nSims <- 1 #number of simulated experiments
> futility1 <-numeric(nSims) #set up empty container for all simulated
> futility
> futility2 <-numeric(nSims) #set up empty container for all simulated
> futility
>
> significant1 <-numeric(nSims) #set up empty container for all simulated
> significance
> significant2 <-numeric(nSims) #set up empty container for all simulated
> significance
>
> for(i in 1:nSims){ #for each simulated experiment
>  # Year 1
>
>  # p1<-response in controls
>  # p2<-response in treated
>  # Generating random deviates from a Uniform(0,1) distribution
>  control.year1<-(runif(16, min = 0, max = 1))
>  treat.year1<-(runif(16, min = 0, max = 1))
>
>  #Generating dichotomous response variables for each group
>  control.respond1<-ifelse(control.year1<=0.05,1,0)
>  treat.respond1<-ifelse(treat.year1<=0.30,1,0)
>
>  #Summing number of responses from each group
>  control.no1<-sum(control.respond1==0)
>  control.yes1<-sum(control.respond1==1)
>  treat.no1<-sum(treat.respond1==0)
>  treat.yes1<-sum(treat.respond1==1)
>
>  #Perform the Fisher's exact test (one sided) with p<0.01
>
> fisher<-matrix(c(control.no1,control.yes1,treat.no1,treat.yes1),nrow=2,ncol=2)
>  f<-fisher.test(fisher,alternative = "greater")
>
>  #year 2
>  if (f$p.value>0.01 && treat.yes1!=0){
># Generating random deviates from a Uniform(0,1) distribution
>control.year2<-(runif(16, min = 0, max = 1))
>treat.year2<-(runif(16, min = 0, max = 1))
>
>#Generating dichotomous response variables for each group
>control.respond2<-ifelse(control.year2<=0.05,1,0)
>treat.respond2<-ifelse(treat.year2<=0.30,1,0)
>
>#Summing number of responses from each group
>control.no2<-sum(control.respond2==0)
>control.yes2<-sum(control.respond2==1)
>treat.no2<-sum(treat.respond2==0)
>treat.yes2<-sum(treat.respond2==1)
>
>#Perform the Fisher's exact test (one sided) with p<0.01
>
> fisher2<-matrix(c(control.no2,control.yes2,treat.no2,treat.yes2),nrow=2,ncol=2)
>f2<-fisher.test(fisher2,alternative = "greater")
>  }
>
>
>  significant2[i]<-ifelse(f2$p.value<0.01,1,0)
>  futility2[i]<-ifelse(treat.yes2==0,1,0)
> }
>
> table(significant1)
> table(futility1)
>
> table(significant2)
> table(futility2)
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] command to change some vars to missing into my dataset

2018-07-05 Thread Jim Lemon
Hi Adam,
Looks like you have a matrix or data frame and want to change one or
more observations to NA. I think this will do the trick:

# assume the matrix or data frame is named "ajdat"
randomNA<-function(x,nNA=1) {
 dimx<-dim(x)
 x[sample(1:dimx[1],nNA),sample(1:dimx[2],nNA)]<-NA
 return(x)
}

So if you want three NAs inserted, call:

randomNA(ajdat,3)

Jim


On Fri, Jul 6, 2018 at 6:28 AM, Adam Z. Jabir  wrote:
> Hi,
>
> I want to simulate missing at random for my dataset. Do you know an easy way 
> to do it?
>
> I want to try not to have the missing’s for the same observations. I mean if 
> one observation is been selected randomly to have missing I don’t want to 
> have all the var of the same obs missing.
>
> I want to be able to choose rate of missing that should be applied.
>
> Thanks,
>
> Adam
>
>
> Envoyé à partir de Outlook
>
> [[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] (no subject)

2018-07-09 Thread Jim Lemon
Hi Laura,
Here's a basic method:

lsdf<-read.table(text="Bird Date Latitude Longitude
eb80976 16/07/2012  50.99   -5.85
eb80976 17/07/2012  52.09   -4.58
eb80976 18/07/2012  49.72   -5.56
eb80976 19/07/2012  51.59   -3.17
eb80976 20/07/2012  52.45   -2.03
eb80976 21/07/2012  56.015  -10.51",
header=TRUE)
library(maps)
map("world",xlim=c(-20,10),ylim=c(45,60))
mtext(side=3,cex=1.5,text="Migration of puffin eb80976",line=2)
lines(lsdf$Longitude,lsdf$Latitude)
library(plotrix)
boxed.labels(lsdf$Longitude,lsdf$Latitude,lsdf$Date,border="white",cex=0.7)
box()
axis(1)
axis(2)

Jim


On Mon, Jul 9, 2018 at 10:13 PM, Laura Steel  wrote:
> I am a beginner to R and I need to map some Atlantic puffin migration routes
> onto a map of the Northern Hemisphere. I have a latitude and longitude point
> per bird, per day. I would like to be able to plot the routes of all my
> birds on one map and ideally so that I can see at which date they are at
> each location.
>
> This is a shortened version of my data for one bird only.
>
> Bird Date  Latitude Longitude
> eb80976 16/07/2012  50.99   -5.85
> eb80976 17/07/2012  52.09   -4.58
> eb80976 18/07/2012  49.72   -5.56
> eb80976 19/07/2012  51.59   -3.17
> eb80976 20/07/2012  52.45   -2.03
> eb80976 21/07/2012  56.015  -10.51
>
> Any help would be much appreciated. I am not totally sure where to start!
> Many thanks.
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Generate N random numbers with a given probability and condition

2018-07-10 Thread Jim Lemon
Hi Nell,
I may not have the right idea about this, but I think you need to do
this in two steps if it can be done. Let's say you want a sequence of
20 (N) numbers between 0 and 10 that sums to 10 (M). You can enumerate
the monotonically increasing sequences like this:

c(0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1)
c(0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2)
...
c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10)

So if you select one of these sequences at random, there will be a
further set of sequences that are permutations of it. By randomly
selecting one of those permutations, I think you can solve your
problem. However, this is going to be computationally intensive, with
the set of permutations being very large for large N. Here is an
example using N = M = 5:

# enumerate the sequences = M
rs5<-list(c(1,1,1,1,1),c(0,1,1,1,2),c(0,0,1,1,3),c(0,0,0,1,4),
 c(0,0,1,2,2),c(0,0,0,2,3),c(0,0,0,0,5))
library(crank)
# generate the permutations for one sequence (120 in this case)
rs5_s1<-permute(rs5[[sample(1:length(rs5),1)]])
# select one of the permutations at random
rs5_s1[sample(1:dim(rs5_s1)[1],1),]
[1] 4 0 1 0 0

Jim

On Wed, Jul 11, 2018 at 10:11 AM, Nelly Reduan  wrote:
> Thank you very much for your reply.
>
>
> By omitting the probability, the expected results could be:
>
>
> c(2, 0, 0, 0, 0, 0, 1, 0, 5, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0)
>
>
> c(0, 0, 1, 0, 0, 1, 1, 0, 6, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0)
>
>
> If I omit the probability, I would like to generate N random positive 
> integers that sum to M and the integers would be selected from a uniform 
> distribution.
>
>
> Many thanks for your time
>
> Nell
>
>
> 
> De : Rolf Turner 
> Envoyé : mercredi 4 juillet 2018 16:11:11
> À : Nelly Reduan
> Cc : r-help@r-project.org
> Objet : Re: [R] Generate N random numbers with a given probability and 
> condition
>
>
> On 05/07/18 10:21, Nelly Reduan wrote:
>
>> Dear all,
>>
>> I would like to generate N random numbers with a given probability and 
>> condition but I'm not sure how to do this.
>> For example, I have N = 20 and the vector from which to choose is seq(0, 10, 
>> 1). I have tested:
>>
>> x <- sample(seq(0, 10, 1), 20, replace=TRUE, prob=rep(0.28, 
>> times=length(seq(0, 10, 1
>>
>> But I don�t know how to put the condition sum(x) <= max(seq(0, 10, 1)).
>> Many thanks for your time.
>
> Your thinking requires considerable clarification.
>
> (1) Note that seq(0,10,1) is just 0, 1, 2, ..., 10.
>
> (2) Hence length(seq(0,10,1)) is 11.
>
> (3) Likewise max(seq(0,10,1)) is 10.
>
> (4) Your prob vector is *constant* --- so specifying "prob" makes
>  no difference --- the result is the same as if you omitted "prob".
>
> (5) You need to think carefully about what you really mean by "random".
>  In what way do you want the final result to be "random"?
>
> I expect that the lecturer who assigned this problem to you  needs to
> clarify his/her thinking as well.
>
> cheers,
>
> Rolf Turner
>
> --
> Technical Editor ANZJS
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Generate N random numbers with a given probability and condition

2018-07-11 Thread Jim Lemon
Hi Nell,
As I said, the number of permutations increases rapidly with the
number of values to be permuted. Using the package "permute", which is
much more sophisticated than the basic function in the crank package,
a vector of length 20 has 2.432902e+18 possible permutations. While
your problem can be solved for small vectors by simply generating all
the permutations and then sampling that set, it is not a general
solution. You may be able to use the functions in the permute package
to handle a 20 element vector, but I am not familiar enough with the
functions to tell you how.

Jim


On Thu, Jul 12, 2018 at 3:14 AM, Nelly Reduan  wrote:
> Many thanks Jim for your help. I am trying to apply the permutations with a
> sequence of 20 but I obtain the error message:
>
>
> Error in matrix(NA, nrow = nrows, ncol = lenx) :
>   invalid 'nrow' value (too large or NA)
> In addition: Warning message:
> In matrix(NA, nrow = nrows, ncol = lenx) :
>   NAs introduced by coercion to integer range
>
> Here is the code:
>
> library(partitions)
> library(crank)
> r <- t(restrictedparts(10, 20))
> r <- split(r, seq(nrow(r)))
> rp <- crank::permute(r[[sample(1:length(r), 1)]])
> rp[sample(1:dim(rp)[1],1),]
>
> In this case, Is it correct to permute the elements of a vector rather than
> to permute a vector ?
>
>
> Many thanks for your time.
>
> Have a nice day
>
> Nell
>
>
> 
> De : Jim Lemon 
> Envoyé : mardi 10 juillet 2018 17:44:13
> À : Nelly Reduan
> Objet : Re: [R] Generate N random numbers with a given probability and
> condition
>
> Hi Nell,
> I may not have the right idea about this, but I think you need to do
> this in two steps if it can be done. Let's say you want a sequence of
> 20 (N) numbers between 0 and 10 that sums to 10 (M). You can enumerate
> the monotonically increasing sequences like this:
>
> c(0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1)
> c(0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2)
> ...
> c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10)
>
> So if you select one of these sequences at random, there will be a
> further set of sequences that are permutations of it. By randomly
> selecting one of those permutations, I think you can solve your
> problem. However, this is going to be computationally intensive, with
> the set of permutations being very large for large N. Here is an
> example using N = M = 5:
>
> # enumerate the sequences = M
> rs5<-list(c(1,1,1,1,1),c(0,1,1,1,2),c(0,0,1,1,3),c(0,0,0,1,4),
>  c(0,0,1,2,2),c(0,0,0,2,3),c(0,0,0,0,5))
> library(crank)
> # generate the permutations for one sequence (120 in this case)
> rs5_s1<-permute(rs5[[sample(1:length(rs5),1)]])
> # select one of the permutations at random
> rs5_s1[sample(1:dim(rs5_s1)[1],1),]
> [1] 4 0 1 0 0
>
> Jim
>
> On Wed, Jul 11, 2018 at 10:11 AM, Nelly Reduan  wrote:
>> Thank you very much for your reply.
>>
>>
>> By omitting the probability, the expected results could be:
>>
>>
>> c(2, 0, 0, 0, 0, 0, 1, 0, 5, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0)
>>
>>
>> c(0, 0, 1, 0, 0, 1, 1, 0, 6, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0)
>>
>>
>> If I omit the probability, I would like to generate N random positive
>> integers that sum to M and the integers would be selected from a uniform
>> distribution.
>>
>>
>> Many thanks for your time
>>
>> Nell
>>
>>
>> 
>> De : Rolf Turner 
>> Envoyé : mercredi 4 juillet 2018 16:11:11
>> À : Nelly Reduan
>> Cc : r-help@r-project.org
>> Objet : Re: [R] Generate N random numbers with a given probability and
>> condition
>>
>>
>> On 05/07/18 10:21, Nelly Reduan wrote:
>>
>>> Dear all,
>>>
>>> I would like to generate N random numbers with a given probability and
>>> condition but I'm not sure how to do this.
>>> For example, I have N = 20 and the vector from which to choose is seq(0,
>>> 10, 1). I have tested:
>>>
>>> x <- sample(seq(0, 10, 1), 20, replace=TRUE, prob=rep(0.28,
>>> times=length(seq(0, 10, 1
>>>
>>> But I don�t know how to put the condition sum(x) <= max(seq(0, 10, 1)).
>>> Many thanks for your time.
>>
>> Your thinking requires considerable clarification.
>>
>> (1) Note that seq(0,10,1) is just 0, 1, 2, ..., 10.
>>
>> (2) Hence length(seq(0,10,1)) is 11.
>>
>> (3) Likewise max(seq(0,10,1)) is 10.
>>
>> (4) Your prob vector is *constant* --- so specifying "prob" makes
>>  no difference --- the result is the same as if 

Re: [R] even display of unevenly spaced numbers on x/y coordinates

2018-07-15 Thread Jim Lemon
Hi Bogdan,
There seem to be three problems. One is that if you want a logarithmic
x axis you shouldn't have a zero (or a negative number) in your data.
The second is that you have to ask for a logarithmic axis. The third
is that you have limited your x axis to less than the range of the
data in "b"::

plot(ecdf(b),xlim=c(0.1,1000),col="red",main=NA,log="x")
plot(ecdf(a),col="green",add=TRUE)

Jim

On Sun, Jul 15, 2018 at 3:16 PM, Bogdan Tanasa  wrote:
> Dear all,
>
> please would you advise on how I could make an even display of unevenly
> spaced number on a graph in R. For example, considering the code below :
>
> BREAKS = c(0, 0.1, 1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300,
> 400, 500)
>
> a <- seq(0,100,0.1)
> b <- seq(0,1000,0.1)
>
> plot(ecdf(a), col="red", xlim=c(0,100), main=NA, breaks=BREAKS)
> plot(ecdf(b), col="green", xlim=c(0,100), add=T, breaks=BREAKS)
>
> I would like to show on X axis (0, 0.1, 1 and 10) spaced in an equal/even
> manner.
>
> thanks !
>
> bogdan
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help in debugging a script

2018-07-16 Thread Jim Lemon
Hi Frederic,
You are asking for the sum of cases in the months September to
December for the years 2012 to 2017. I get a plot that shows that
from:

plot(busoro[,"X"],busoro[,"Sep"] + busoro[,"Oct"] + busoro [,"Nov"] +
busoro[,"Dec"],type="b",ylab="Malaria Cases",xlab="Year")

What sort of plot were you expecting?

Jim

On Mon, Jul 16, 2018 at 4:42 PM, Frederic Ntirenganya  wrote:
> Dear Friends,
>
> I would like to ask for help.
> I am plotting monthly data as seasonal by adding particular months but I am
> getting an unexpected graph. What I want is why and what can be another
> alternative?
>
> Here is the data and R script
>
> busoro <- read.csv("G:/Fredo/PAPER/Malaria climate paper/data/NYANZA
> DATA/busoro2.csv", header=T)
>
> # x axis
> y = 2012:2017
> #plot
> plot(y,busoro[,"Sep"] + busoro[,"Oct"] + busoro [,"Nov"] +
> busoro[,"Dec"],type="b",
>  ylab="Malaria Cases",xlab="Year")
>
> grid(10,10,lwd=2)
>
> dput((head(busoro)))structure(list(X = 2012:2017, Jan = c(73L, 754L,
> 1016L, 2651L,
> 1201L, 3405L), Feb = c(129L, 959L, 1276L, 3917L, 1262L, 3715L
> ), Mar = c(238L, 770L, 1670L, 3975L, 1379L, 3571L), Apr = c(705L,
> 875L, 1117L, 3549L, 1021L, 2789L), May = c(915L, 1034L, 1379L,
> 3092L, 2091L, 3487L), Jun = c(985L, 741L, 1612L, 4351L, 1599L,
> 1662L), Jul = c(402L, 115L, 901L, 3394L, 623L, 817L), Aug = c(337L,
> 218L, 966L, 1002L, 732L, 755L), Sep = c(353L, 580L, 2284L, 2427L,
> 2033L, 1134L), Oct = c(1016L, 1243L, 2788L, 3571L, 2940L, 1763L
> ), Nov = c(682L, 1336L, 2229L, 2730L, 2866L, 1469L), Dec = c(641L,
> 1049L, 1701L, 1380L, 2153L, 1321L)), .Names = c("X", "Jan", "Feb",
> "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
> "Dec"), row.names = c(NA, 6L), class = "data.frame")
>
>
> Thanks in advance.
>
>
> Frederic Ntirenganya
> Nyanza District,
> Data Mnager.
> Mobile:(+250)788757619
> Email: fr...@aims.ac.za
> https://sites.google.com/a/aims.ac.za/fredo/
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] GGPlot plot

2018-07-18 Thread Jim Lemon
Hi Francesca,
This looks like a fairly simple task. Try this:

fpdf<-read.table(text="PASP   SUBJC
 0  0
 4  1
 0  0
 8  0
 4  0
 0  1
 0  1",
 header=TRUE)
# get the number of positive PASP results by group
ppos<-by(fpdf$SUBJC,fpdf$PASPpos,sum)
# get the number of subjects per group
spg<-c(sum(fpdf$SUBJC==0),sum(fpdf$SUBJC==1))
barplot(ppos/spg,names.arg=c(0,1),xlab="Group",
 ylab="Proportion PASP > 0",main="Proportion of PASP positive by group")

Jim

On Thu, Jul 19, 2018 at 2:47 AM, Francesca  wrote:
> Dear R help,
>
> I am new to ggplot so I apologize if my question is a bit obvious.
>
> I would like to create a plot where a compare the fraction of the values of a 
> variable called PASP out of the number of subjects, for two groups of subject 
> codified with a dummy variable called SUBJC.
>
> The variable PASP is discrete and only takes values 0,4,8..
>
> My data are as following:
>
>
>
> PASP   SUBJC
>
>
>
> 0  0
>
> 4  1
>
> 0  0
>
> 8  0
>
> 4  0
>
> 0  1
>
> 0  1
>
> .   .
>
> .   .
>
> .   .
>
>
>
>
> I would like to calculate the fraction of positive levels of PASP out of the 
> total number of observations, divided per values of SUBJ=0 and 1. I am new to 
> the use of GGPlot and I do not know how to organize the data and what to use 
> to summarize these data as to obtain a picture as follows:
>
>
>
>
>
> I hope my request is clear. Thanks for any help you can provide.
>
> Francesca
>
>
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] GGPlot plot

2018-07-18 Thread Jim Lemon
Hi again,
Sorry, forgot this line:

 fpdf$PASPpos<-fpdf$PASP > 0

just after reading in the data frame.

Jim


On Thu, Jul 19, 2018 at 9:04 AM, Jim Lemon  wrote:
> Hi Francesca,
> This looks like a fairly simple task. Try this:
>
> fpdf<-read.table(text="PASP   SUBJC
>  0  0
>  4  1
>  0  0
>  8  0
>  4  0
>  0  1
>  0  1",
>  header=TRUE)
> # get the number of positive PASP results by group
> ppos<-by(fpdf$SUBJC,fpdf$PASPpos,sum)
> # get the number of subjects per group
> spg<-c(sum(fpdf$SUBJC==0),sum(fpdf$SUBJC==1))
> barplot(ppos/spg,names.arg=c(0,1),xlab="Group",
>  ylab="Proportion PASP > 0",main="Proportion of PASP positive by group")
>
> Jim
>
> On Thu, Jul 19, 2018 at 2:47 AM, Francesca  
> wrote:
>> Dear R help,
>>
>> I am new to ggplot so I apologize if my question is a bit obvious.
>>
>> I would like to create a plot where a compare the fraction of the values of 
>> a variable called PASP out of the number of subjects, for two groups of 
>> subject codified with a dummy variable called SUBJC.
>>
>> The variable PASP is discrete and only takes values 0,4,8..
>>
>> My data are as following:
>>
>>
>>
>> PASP   SUBJC
>>
>>
>>
>> 0  0
>>
>> 4  1
>>
>> 0  0
>>
>> 8  0
>>
>> 4  0
>>
>> 0  1
>>
>> 0  1
>>
>> .   .
>>
>> .   .
>>
>> .   .
>>
>>
>>
>>
>> I would like to calculate the fraction of positive levels of PASP out of the 
>> total number of observations, divided per values of SUBJ=0 and 1. I am new 
>> to the use of GGPlot and I do not know how to organize the data and what to 
>> use to summarize these data as to obtain a picture as follows:
>>
>>
>>
>>
>>
>> I hope my request is clear. Thanks for any help you can provide.
>>
>> Francesca
>>
>>
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Automate running files in R

2018-07-22 Thread Jim Lemon
Hi Serena,
I think the directory structure you have described is something like this:

mov_study___
 | |
 mov1  ...mov9
 /   \/ \
mov1_csv  mov1_graphs mov9_csv  mov9_graphs

If so, you can put your R scripts in the mov_study directory and
change directories like this:

for(movdir in paste0("mov",1:9,) {
 setwd(movdir)
 source("R1")
 source("R2")
 setwd("..")
}

In R1 and R2 add a "movdir" argument set the target directories for
your output like this:
 R1<-function(...,movdir=movdir)
 R2<-function(...,movdir=movdir)

 path_to_csv<-paste(movdir,"csv",sep="_")
 path_to_graph<-paste(movdir,"graphs",sep="_")

and when you write an output file:
# for CSV files
filename<-paste(path_to_csv,csvfilename,sep="/")
# for graph files
filename<-paste(path_to_graph,graphfilename,sep="/")

Obviously I can't test this on your directory structure, but I think
it will do what you want.

Jim

On Mon, Jul 23, 2018 at 6:26 AM, Serena De Stefani
 wrote:
> I need to automate a process in R. Basically I have a an R script (I will
> call it R1) that needs three separate files to run. These three files are
> the results output of one trial in my study.
>
> So from each run in R I obtain the summary results for one trial, in a csv
> file, plus 32 graphs for each decision point in the trial.
>
> One subject goes through of nine trials. I was thinking about putting all
> the files generated by one subject in one big folder, so I will have 27
> files (three files times nine trials). This way I won't have to change
> working directory multiple times (I wonder if there is a way to have R open
> a folder with a certain name as directory, run a scripts, move the
> directory to the next folder, run the script again...)
>
> The trials are specified by the labels: AA AB AM BA BB BM MA MB MM. So for
> subject 1, trial 1, I will have three files with the ending
> …mov1_AA
>
> For subject one, trial 2, R should choose the three files with the ending …
> mov1_AB and so on.
>
> At each run, R should save the csv summary output in a folder called
> “summary_mov1” and name the files summary_mov1_AA, summary_mov1_AB etc. R
> should save the 32 graphs in a different folder, named mov1_graphs,
> graph1_mov1_AA, graph1_mov1_AB and so on (ideally, at this point another R
> script (R2) should take these nine csv files and build some graphs out of
> them).
>
> Once R has run R1 script nine times, I would proceed to a new subject.
>
> So basically: use R1 with three mov1 files, get a summary csv file in a
> summary folder (plus 32 graphs in a different folder).
>
> Do this nine times. Once one get the nine csv summary files in the same
> folder, use R2 to average them and build a graph.
>
> Then do this for each subject (right now I have 7).
>
> I have never done this type of automation so I am a bit lost. Any
> suggestions? Any examples you can point me to? Which would be the best
> workflow? At which level should I automate and which things should I rather
> do by hand?
>
> Thank you,
> Serena DeStefani
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help with package ranks

2017-04-05 Thread Jim Lemon
Hi Davide,
The error message is probably due to a zero length dimension in:

W[,ind.positives]

I would look at W (data frame?) to see where this might occur. That
is, does W have a set of proteins with _no_ annotations? Perhaps
manually removing that set will get the function running.

Jim


On Wed, Apr 5, 2017 at 5:14 AM, davide f  wrote:
> Hello, I'm Davide.
> I'm using the package RANKS, in particular the functions do.GBA, do.RW,
> do.RANKS. To the funcs are given 2 different Matrix. One is a a simmetryc
> adjacency Matrix(called "M"), where rows and columns are protein, and the
> other is an annotation Matrix(called "ann"), where protein are rows(the
> same of the first Matrix) and and the annotations are columns.
>
> I write a script in order to filter both the matrices, choosing only
> protein with 5 or more annotations.
>
> To be more specific, using the functions, data=M, labels=ann.
>
> But, running the script, it gives me an error message about the functions
> of interest:
>
> Error in apply(W[, ind.positives], 1, sum) :
>   dim(X) deve avere lunghezza positiva
>
>
> In paritcular it gives me the error during the FOR cycle, when it
> works on the 6th column.
>
>
> How can I resolve it? what is the reason?
>
>
> Thank you in advance, best regards,
>
> Davide.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Package Query

2017-04-05 Thread Jim Lemon
Hi Ruchika,
Maybe the hdeco package will help.

Jim


On Wed, Apr 5, 2017 at 2:28 PM, Ruchika Salwan
 wrote:
> Hey,
>
> Is there any package in R that handles graph decomposition? A package
> created specifically for flat/hierarchical decomposition of graphs.
>
> Thanks,
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Binning Data and Event rates

2017-04-17 Thread Jim Lemon
Hi Pateek,
Try this:
ppdat<-read.table(text="Values Churn
 21  1
 22  1
 31.2   1
 32  1
 35  0
 43  1
 45   0
 67  1
 67   0
 76   0
 89   1",
 header=TRUE)
ppdat$Valbin<-cut(ppdat$Values,breaks=c(20.9,43.7,66.3,89.1))
binPct<-function(x) return(100*sum(x)/length(x))
binnedPct<-by(ppdat$Churn,ppdat$Valbin,binPct)
bpctdf<-data.frame('Binned data'=names(binnedPct),
 'churn%'=as.vector(binnedPct))
bpctdf

Jim

On Tue, Apr 18, 2017 at 5:20 AM, prateek pande  wrote:
> I have a data, in the form mentioned below.
>
> Values Churn
> 21  1
> 22  1
> 31.2   1
> 32  1
> 35  0
> 43  1
> 45   0
> 67  1
> 67   0
> 76   0
> 89   1
>
> Now i want to bin the values variables into bins and corresponding that
> want the churn percentage, like mentioned below
>Binned data  churn%
>   (20.9,43.7]0.83
>   (43.7,66.3]0
>   (66.3,89.1]0.50
>
> Please help
>
> « Return to Rcom-l   |  3
> v
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] Multiple Histograms in R

2017-04-19 Thread Jim Lemon
Hi Prateek,
There is some difficulty with including the empty categories in the
factors generated. I couldn't get these even with drop=FALSE, so I had
to go through the "xtab" function. You can do it with the "table"
function in the base package, but it is a little more trouble. See if
this is what you want>

ppdat<-read.table(text="mou_mean,totalmrc_mean,rev_range,mou_range,Churn
23,24,25,27,1
45,46,47,49,1
43,44,45,47,1
45,46,47,49,0
56,57,58,60,0
67,68,69,71,1
67,68,69,71,0
44,45,46,48,1
33,34,35,37,0
90,91,92,94,1
87,88,89,91,1
76,77,78,80,1
33,34,35,37,1
44,45,46,48,1",
sep=",",header=TRUE)
ppdat$mou_mean_cut<-cut(ppdat$mou_mean,breaks=seq(23,103,10),include.lowest=TRUE)
ppdat$totalmrc_mean_cut<-cut(ppdat$totalmrc_mean,breaks=seq(23,103,10))
ppdat$rev_range_cut<-cut(ppdat$rev_range,breaks=seq(23,103,10))
ppdat$mou_range_cut<-cut(ppdat$mou_range,breaks=seq(23,103,10))
library(prettyR)
ppx<-xtab(Churn~mou_mean_cut,ppdat)
mou_mean_agg<-100*ppx$counts[2,]/colSums(ppx$counts)
mou_mean_agg[is.nan(mou_mean_agg)]<-0
ppx<-xtab(Churn~totalmrc_mean_cut,ppdat)
totalmrc_mean_agg<-100*ppx$counts[2,]/colSums(ppx$counts)
totalmrc_mean_agg[is.nan(totalmrc_mean_agg)]<-0
ppx<-xtab(Churn~rev_range_cut,ppdat)
rev_range_agg<-100*ppx$counts[2,]/colSums(ppx$counts)
rev_range_agg[is.nan(rev_range_agg)]<-0
ppx<-xtab(Churn~mou_range_cut,ppdat)
mou_range_agg<-100*ppx$counts[2,]/colSums(ppx$counts)
mou_range_agg[is.nan(mou_range_agg)]<-0
ppmat<-matrix(c(mou_mean_agg,totalmrc_mean_agg,rev_range_agg,
 mou_range_agg),nrow=4,byrow=TRUE)
library(plotrix)
barp(ppmat,col=rainbow(4),main="Multiple histogram",ylim=c(0,105),
 names.arg=levels(ppdat$mou_mean_cut),ylab="Percent churn")
legend(2.5,107,c("mou_mean","totalmrc_mean","rev_range","mou_range"),
 fill=rainbow(4))

Jim


On Wed, Apr 19, 2017 at 11:05 PM, prateek pande  wrote:
> Hi,
>
> I have a data as mentioned below(at the bottom)
>
> Now out of that data i have to create multiple histograms in a single view
> in  R. On that histogram i need on x -axis binned data with Breaks 10 and
> on y axis event rate . Here churn is dependent variable.
>
>
> *for example, for mou_mean , on x -axis on histogram i need Bins(mou_mean)
> and on y - axis in need Churn%age. *
> *Bins(mou_mean)*
>
> *Churn %age*
> 23-43  0.23%
> 33-53  0.5%
> 43-63   0.3%
> 53-73   0.4%
> 63-83   0.7%
> 83-1030.8%
>
> Please help
>
>
> *mou_mean*
>
> *totalmrc_mean*
>
> *rev_range*
>
> *mou_range*
>
> *Churn*
>
> 23
>
> 24
>
> 25
>
> 27
>
> 1
>
> 45
>
> 46
>
> 47
>
> 49
>
> 1
>
> 43
>
> 44
>
> 45
>
> 47
>
> 1
>
> 45
>
> 46
>
> 47
>
> 49
>
> 0
>
> 56
>
> 57
>
> 58
>
> 60
>
> 0
>
> 67
>
> 68
>
> 69
>
> 71
>
> 1
>
> 67
>
> 68
>
> 69
>
> 71
>
> 0
>
> 44
>
> 45
>
> 46
>
> 48
>
> 1
>
> 33
>
> 34
>
> 35
>
> 37
>
> 0
>
> 90
>
> 91
>
> 92
>
> 94
>
> 1
>
> 87
>
> 88
>
> 89
>
> 91
>
> 1
>
> 76
>
> 77
>
> 78
>
> 80
>
> 1
>
> 33
>
> 34
>
> 35
>
> 37
>
> 1
>
> 44
>
> 45
>
> 46
>
> 48
>
> 1
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Reg. help for SWAT Calibration

2017-04-26 Thread Jim Lemon
Hi Sanjeev,
The video that you attached seems to contain the information that you
want. If you contact Kazi Rahman (the creator of the video) who seems
to be at the University of Geneva currently, you may be able to get
the information that you want.

Jim

On Wed, Apr 26, 2017 at 4:27 PM, Sanjeev Kumar
 wrote:
> Sir/Mam
>   I am a Research Scholar at Central University of Karnataka and I am
> working on SWAT (Soil And Water Assessment tool) and I need 'R' for the
> Calibration purpose but for 'R' I need a code. So if it is possible to send
> that code pls send me.
>
>
>
> https://www.youtube.com/watch?v=5NFn9paBR98&t=15s
> This is the video link where i came to know about 'R'
>
>
>
> Thanks
>
> Yours Sincerely
> Sanjeev Kumar
> Research Associate
> Central University of Karnataka
> Karnataka India
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem in conversion of regulate time series and forecasting using Date Time [Timestamp values]:R

2017-04-27 Thread Jim Lemon
Hi Dhivya,
I'm not that familiar with the "gg.ts" function, but you are passing
character values to the "frequency" and "start" arguments. If there is
no automatic conversion to numeric values, that would cause the error.
Similarly, your "timestamps" variable may have been read in as a
factor, which often causes trouble with date conversions. Try
as.character(gg$timestamps) instead of just gg$timestamps.

Jim


On Thu, Apr 27, 2017 at 4:51 PM, Dhivya Narayanasamy
 wrote:
> Hi,
> I am new to R. Kindly help me with the plot that gives wrong x-axis
> values.  I have a data frame "gg", that looks like this:
>
>> head(gg)
>
>timestamps  value
> 1 2017-04-25 16:52:00 -0.412
> 2 2017-04-25 16:53:00 -0.4526667
> 3 2017-04-25 16:54:00 -0.4586667
> 4 2017-04-25 16:55:00 -0.4606667
> 5 2017-04-25 16:56:00 -0.505
> 6 2017-04-25 16:57:00 -0.507
>
> I need to plot this as a Time series data to do forecasting. The steps are
> as follows:
>
> 1) gg$timestamps <- as.POSIXct(gg$timestamps, format = "%Y-%m-%d %H-%M-%S")
>  #changing "Timestamps" column 'factor' to 'as.POSIXct'.
>
> 2) gg.ts <- xts(x=gg$value, order.by = gg$timestamps) #converting the
> dataframe to time series (Non Regular Time series)
>
> 3) fitting <- auto.arima(gg.ts) #fitting the time series model using
> auto.arima
>
> 4) fore <- forecast(fitting, h=30, level = c(80,95))  #Forecasting
>
> 5) I am using plotly to this forecast model (Inspired from here :
> https://plot.ly/r/graphing-multiple-chart-types/#plotting-forecast-objects)
>
> plot_ly() %>%
>   add_lines(x = time(gg.ts), y = gg.ts,
> color = I("black"), name = "observed") %>%
>   add_ribbons(x = time(fore$mean), ymin = fore$lower[, 2], ymax =
> fore$upper[, 2],
>   color = I("gray95"), name = "95% confidence") %>%
>   add_ribbons(x = time(fore$mean), ymin = fore$lower[, 1], ymax =
> fore$upper[, 1],
>   color = I("gray80"), name = "80% confidence") %>%
>   add_lines(x = time(fore$mean), y = fore$mean, color = I("blue"), name =
> "prediction")
>
>
> The plot comes out wrong: 1) x axis labels are wrong. It shows some
> irrelevant values on axis. 2) the plot is not coming out.
> Also I tried to convert "gg.ts" to a regulate time series which throws
> error :
>
>> gg.xts <- ts(gg.ts, frequency = '1', start = ('2017-04-25 16:52:00'))
> Error in 1/frequency : non-numeric argument to binary operator
>
> Please help me how to use Date Time values in converting to regulate time
> series for forecasting.
>
>
> Regards
>> Dhivya
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] gap.barplot with means and standard error bars

2017-04-28 Thread Jim Lemon
Hi Bianca,
Try this:

gap.barplot(c(mean(SA),mean(AA),mean(CA)),
 gap=c(1,250),xlim=c(0.5,3.5),xaxlab=c("SA","AA","CA"),
 ytics=c(0,255,260,265),yaxlab=c(0,255,260,265))
barlabels(1:3,c(5,5,5),
 paste(c(mean(SA),mean(AA),mean(CA)),
 round(c(sd(SA),sd(AA),sd(CA)),3)))

It's a bit rough, but I don't have time for refinement tonight.

Jim

On Fri, Apr 28, 2017 at 5:10 AM, Biank M  wrote:
> Hi..
>
>
> I've been trying to create a barplot with the following data:
>
>
> SA<- c(0.06, 0.061, 0.06, 0.06, 0.06)
> AA<- c(0.29, 0.275, 0.271, 0.274, 0.276)
> CA<- c(266.783, 257.726, 276.331, 268.859, 265.042)
>
>
> I want a bar for "SA", a bar for "AA", and a bar for "CA" (x- axis). The 
> height of the bar must be represented by the mean of each vector data and 
> include SE bars. Since there are very very large differences in numbers , I 
> want to add a gap between 1 and 250 (y-axis).
>
>
> I know that the gap.barplot function is used to produce the gap, but I don't 
> know how to include the means and SE bars.
>
> Can you help me creating this plot??
>
>
> Thank you very much!!
>
>
> Greetings,
>
> Bianca
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Whitespace

2017-05-01 Thread Jim Lemon
Hi Miguel,
You don't seem to have defined "J" before line 2. Maybe that is the problem.

Jim


On Mon, May 1, 2017 at 2:57 PM, Miguel Angel Hombrados Herrera
 wrote:
> Hello
>
>
> Ive been working on a stan program in Rstudio. Im kind of new on this, so 
> probably my question is trivial, However I was not able to find information 
> about this.
>
> The error Im getting when I run my stan code is:
>
>
> PARSER EXPECTED: whitespace to end of file.
> FOUND AT line 2:
>
>
> The code is:
>
> iter=500
> alphamcmc=matrix(0,ncol=J,nrow=iter)
> betamcmc=NULL
> mu_alpha=NULL
> sigma_alpha_2=NULL
> sigma_y_2=NULL
> #set initial values
> alphamcmc[1,]=rep(mean(y),J)
> betamcmc[1]=70
> mu_alpha[1]=mean(y)
> sigma_alpha_2[1]=300
> sigma_y_2[1]=350
> #mcmc iteration
> for(m in 2:iter){
> #update alpha vector
> for(j in 1:J){
> sj=sum(source==j)
> var=1/(sj/sigma_y_2[m-1]+1/sigma_alpha_2[m-1])
> temp=0
> for(i in 1:N){temp=temp+1*(source[i]==j)*(y[i]-betamcmc[m-1]*x[i])}
> #sum up (y_i-beta x_i ) for those belonging to group j
> mean=var*(temp/sigma_y_2[m-1]+mu_alpha[m-1]/sigma_alpha_2[m-1])
> alphamcmc[m,j]=rnorm(1,mean,sqrt(var))
> }
> #update beta
> var=sigma_alpha_2[m-1]/(sum(x^2))
> mean=sum(x%*%(y-alphamcmc[m,source])/sum(sum(x^2)))
> betamcmc[m]=rnorm(1,mean,sqrt(var))
> #update mu_alpha
> #update sigma_alpha_2
> sigma_alpha_2[m]=rinvgamma(1,shape=J/2,rate=sum((alphamcmc[m,]
> -mu_alpha[m])^2/2))
> #update sigma_y_2
> sigma_y_2[m]=rinvgamma(1,shape=N/2,rate=sum((y-alphamcmc[m,source]-
> betamcmc[m]*x)^2/2))
> }
> nburn=200
> apply(alphamcmc[(nburn+1):iter,],2,mean)
> apply(betamcmc[(nburn+1):iter],2,mean)
>
> Ive been searching for wrong spaces or tabulations, but I was not able to 
> find anything.
>
> I really would appreciate your help.
> Thaknk 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.

__
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] Example of the use of the "crt" graphical parameter?

2017-05-01 Thread Jim Lemon
Hi Michael,
The arctext function (plotrix) does something similar, and the code
could be modified to do what you request. If you do want a working
function, it wouldn't be too hard to program.

Jim


On Tue, May 2, 2017 at 6:57 AM, Michael Hannon
 wrote:
> Hi, folks.  This is an issue that we've defined away, but I recently
> thought it would be useful to rotate characters in some marginal text
> in a base-R plot.  I made a few stabs on using the "crt" parameter but
> was unsuccessful.
>
> I'm deliberately omitting details of my attempts, as I want just to
> focus on the following: if you know of any working example of the use
> of that parameter. will you please send me a link to it?  Thanks.
>
> (Note that there are *many* links to Cathode Ray Tubes,)
>
> -- Mike
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] nested for loop with data table

2017-05-02 Thread Jim Lemon
Hi Ek,
I think you want your example to look like this:

Sample<-read.table(text=
"Num Color Grade Value Month Day
1 yellow A 20 May 1
2 green B 25 June 2
3 green A 10 April 3
4 black A 17 August 3
5 red C 5 December 5
6 orange D 0 January 13
7 orange E 12 January 5
8 orange F 11 February 8
9 orange F 99 July 23
10 orange F 70 May 7
11 black A 77 June 11
12 green B 87 April 33
13 black A 79 August 9
14 green A 68 December 14
15 black C 90 January 31
16 green D 79 January 11
17 black E 101 February 17
18 red F 90 July 21
19 red F 112 February 13
20 red F 101 July 20",
header=TRUE)
AAA<-Sample[Sample$Num < 5 & Sample$Day < 3,]
BBB<-Sample[Sample$Num > 15 & Sample$Day > 13,]
for(i in 1:length(AAA)) {
 for(j in 1:length(BBB)) {
  ...
 }
}

except in data.table notation. However, I can't work out what you want
to do in the loop.

Jim


On Wed, May 3, 2017 at 2:35 AM, Ek Esawi  wrote:
> I have a huge data file; a sample is listed below. I am using the package
> data table to process the file and I am stuck on one issue and need some
> feedback. I used fread to create a data table. Then I divided the data
> table (named File1) into 10 general subsets using common table commands
> such as:
>
>
>
> AAA <- File1[Num<5&day>15]
>
> BBB <- File1[Num>15&day<10]
>
> …..
>
> …..
>
> …..
>
> …..
>
> …..
>
> …..
>
>
>
> I wanted to divide and count each of the above subsets based on a set of
> parameters common to all subsets. I did the following to go through each
> subset and it works:
>
> For (I in 1: length (AAA)) {
>
>   aa <- c(AAA[color==”green”&grade==”a”,month==”Januray” .N],[
> AAA[color==”green”&grade==”b”& month==”June”’ .N])
>
> }
>
>
>
> The question: I don’t want to have a separate loop for each subset (10
> loops). Instead, I was hoping to have 2 nested loops in the form below:
>
>
>
> For (I in 1:N)){
>
>   For (j in 1:M){
>
>
>
> }
>
> }
>
>
>
>  Sample
>
>
> Num
>
> Color
>
> Grade
>
> Value
>
> Month
>
> Day
>
> 1
>
> yellow
>
> A
>
> 20
>
> May
>
> 1
>
> 2
>
> green
>
> B
>
> 25
>
> June
>
> 2
>
> 3
>
> green
>
> A
>
> 10
>
> April
>
> 3
>
> 4
>
> black
>
> A
>
> 17
>
> August
>
> 3
>
> 5
>
> red
>
> C
>
> 5
>
> December
>
> 5
>
> 6
>
> orange
>
> D
>
> 0
>
> January
>
> 13
>
> 7
>
> orange
>
> E
>
> 12
>
> January
>
> 5
>
> 8
>
> orange
>
> F
>
> 11
>
> February
>
> 8
>
> 9
>
> orange
>
> F
>
> 99
>
> July
>
> 23
>
> 10
>
> orange
>
> F
>
> 70
>
> May
>
> 7
>
> 11
>
> black
>
> A
>
> 77
>
> June
>
> 11
>
> 12
>
> green
>
> B
>
> 87
>
> April
>
> 33
>
> 13
>
> black
>
> A
>
> 79
>
> August
>
> 9
>
> 14
>
> green
>
> A
>
> 68
>
> December
>
> 14
>
> 15
>
> black
>
> C
>
> 90
>
> January
>
> 31
>
> 16
>
> green
>
> D
>
> 79
>
> January
>
> 11
>
> 17
>
> black
>
> E
>
> 101
>
> February
>
> 17
>
> 18
>
> red
>
> F
>
> 90
>
> July
>
> 21
>
> 19
>
> red
>
> F
>
> 112
>
> February
>
> 13
>
> 20
>
> red
>
> F
>
> 101
>
> July
>
> 20
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] adding counter to df by group

2017-05-03 Thread Jim Lemon
Hi Davide,
You wouldn't be dealing with the Stroop test, would you?

stroop.df<-data.frame(subject=rep(paste("S",1:10,sep=""),each=12),
 color=rep(c("R","G","B"),40),cong=rep(rep(c("C","I"),each=3),20))
stroop.df$colcong<-paste(stroop.df$color,stroop.df$cong,sep="")
stroop.rc<-stroop.df[stroop.df$colcong=="RC",]
table(stroop.df$subject[stroop.df$colcong=="RC"])

Jim

On Thu, May 4, 2017 at 4:24 AM, Davide Piffer  wrote:
> I need to count the trials in an experiment, separately for each
> subject. I thought about using the function "by" but I could not
> manage to achieve this. Instead, I tried "split" and I got closer to a
> solution but still not getting there yet.
> The following code should create a variable "miniblock" with the
> trial/miniblock number.
> split_cong=split(red_congruent,red_congruent$subject_nr)
> miniblock_cong=lapply(split_cong,seq_along)
> red_congruent$miniblock=unlist(miniblock_cong)
>
> However, I get the following error message: Error in
> `$<-.data.frame`(`*tmp*`, "miniblock", value = c(1L, 2L, 3L,  :
>   replacement has 460 rows, data has 500
>
> Is there a more efficient way to achieve the result? Maybe with "by" or dplyr?
>
> Thanks a lot in advance!
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] RCommander issue

2017-05-03 Thread Jim Lemon
Hi Thambu (David?),
While I like the misspelling of CRAN (there is a lot CRAMmed on it),
could this be your problem?

Jim

On Thu, May 4, 2017 at 12:55 AM, thambu david via R-help
 wrote:
> Dear AllI am learning R commander and have un-installed my earlier version of 
> R and installed the 3.4 version for windos. I have an older PC that runs on 
> windows XP professionalThe problem is that when i try and work with R, when i 
> set the CRAM mirror or choose a program to Install i keep getting an error 
> message "InternetOpenUrl failed: 'A connection with the server could not be
>>established'"I have checked that it is not a firewall issue and the internet 
>>administrator says all is well with the Internet and they do not have any 
>>problem from their sideIs this an issue with R? Is there some setting i need 
>>to do to get this sorted out?I would be thankful for you helpsincerelyThambu
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] setting the values of a secondary "y" axis

2017-05-07 Thread Jim Lemon
Hi Antonio,
Have a look at twoord.plot (plotrix). It may make your repeated plots easier.

Jim


On Sun, May 7, 2017 at 7:50 AM, Antonio Silva  wrote:
> Hello
>
> I want to make a plot with two "y" axes. The labels at axis 4 should be the
> values from axis 2 multiplied by a scale factor (as 3.5).
>
> In the example below I draw axis 4 exactly as axis 2. But I could not find
> a way to multiply its values by 3.5 (e.g.).
>
> plot(rnorm(100,30,5))
> axis(4) # I'd like to have these values multiplied by a scale factor
>
> I will produce plots for different data sets in a looping and y values will
> vary so I  cannot "freeze" axis 4 labels because they (values and scale
> factor) will vary  from plot to plot.
>
> Thanks in advance for any help. All the best.
>
> Antonio
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Visualizing a graph in the coordinate system given by x using vanila R

2017-05-07 Thread Jim Lemon
Hi Ante,
As this is a homework problem, you will probably get a number of
negative replies. You might want to look at the color.scale.lines
function in the plotrix package. Perhaps you will find some clues in
the code.

Jim

On Mon, May 8, 2017 at 9:22 AM, Ante Dilber  wrote:
> So I have the following problem, I need to write a function plotGraph(x , y)
> in R with the following properties:
>
> The argument x may be a matrix or data frame with two columns containing
> coordinates of vertices of a graph. The argument y must be a quadratic
> adjacency matrix that has as many rows and columns as x has rows. Values of
> 0 of NA stand for “no connection”. Positive values stand for the connection
> strength. Negative values are not allowed.
>
> After that I need to visualize the resulting graph in the coordinate system
> given by x, where connection strengths should be visualized by different
> line widths and check inputs for validity.
>
> Note: I can only use packages that are pre-loaded with R (e.g. graphics ,
> grDevices).
>
> Can someone please explain me how to do that ? I understand that y is the
> information about the nodes in the network and their connections (vertices
> & edges), x is the information about the network layout, i.e. where to
> place the nodes. But I don't know how to do the visualization part with the
> different connection strenghts ?
>
> Thanks in advance :)
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] creating a color gradient in geom_ribbon

2017-05-10 Thread Jim Lemon
Hi Kristi,
It can be done, but it is messy:

pl = data.frame(Time = 0:10, menle = rnorm(11))
pl$menlelb = pl$menle -1
pl$menleub = pl$menle +1
rg<-0.95
blue<-1
plot(pl$Time,pl$menlelb,ylim=range(c(pl$menlelb,pl$menleub)),type="l",
 lwd=7,col=rgb(rg,rg,blue))
lines(pl$Time,pl$menlelb,lwd=7,col=rgb(rg,rg,blue))
rg<-seq(0.9,0.3,length.out=9)
offset<-seq(0.88,0.08,by=-0.1)
for(i in 1:9) {
 lines(pl$Time,pl$menle+offset[i],lwd=7,col=rgb(rg[i],rg[i],blue))
 lines(pl$Time,pl$menle-offset[i],lwd=7,col=rgb(rg[i],rg[i],blue))
}
lines(pl$Time,pl$menle,lwd=6,col=rgb(0,0,blue))

For the ggplot solution, this might work:

ggplot(pl, aes(Time)) +
  geom_line(aes(y=menle+1), colour=rgb(0.95,0.95,1), width=7) +
  geom_line(aes(y=menle-1), colour=rgb(0.95,0.95,1), width=7) +
  geom_line(aes(y=menle+0.88), colour=rgb(0.9,0.9,1), width=7) +
  geom_line(aes(y=menle-0.88), colour=rgb(0.9,0.9,1), width=7) +
  geom_line(aes(y=menle+0.78), colour=rgb(0.825,0.825,1), width=7) +
  geom_line(aes(y=menle-0.78), colour=rgb(0.825,0.825,1), width=7) +
  geom_line(aes(y=menle+68), colour=rgb(0.75,0.75,1), width=7) +
  geom_line(aes(y=menle-68), colour=rgb(0.75,0.75,1), width=7) +
  geom_line(aes(y=menle+0.58), colour=rgb(0.675,0.675,1), width=7) +
  geom_line(aes(y=menle-0.58), colour=rgb(0.675,0.675,1), width=7) +
  geom_line(aes(y=menle+0.48), colour=rgb(0.6,0.6,1), width=7) +
  geom_line(aes(y=menle-0.48), colour=rgb(0.6,0.6,1), width=7) +
  geom_line(aes(y=menle+0.38), colour=rgb(0.525,0.525,1), width=7) +
  geom_line(aes(y=menle-0.38), colour=rgb(0.525,0.525,1), width=7) +
  geom_line(aes(y=menle+0.28), colour=rgb(0.45,0.45,1), width=7) +
  geom_line(aes(y=menle-0.28), colour=rgb(0.45,0.45,1), width=7) +
  geom_line(aes(y=menle+0.18), colour=rgb(0.375,0.375,1), width=7) +
  geom_line(aes(y=menle-0.18), colour=rgb(0.375,0.375,1), width=7) +
  geom_line(aes(y=menle+0.08), colour=rgb(0.3,0.3,1), width=7) +
  geom_line(aes(y=menle-0.08), colour=rgb(0.3,0.3,1), width=7) +
  geom_line(aes(y=menle), colour="blue") )

but I can't test it.

Jim

On Thu, May 11, 2017 at 6:05 AM, Kristi Glover
 wrote:
> Hi R Users,
>
> I was trying to create a figure with geom_ribbon. There is a function "fill", 
> but I want to make the shaded area with a gradient (increasing dark color 
> towards a central line, inserted of having a color). Is there any possibility?
>
>
> In the given example, I want the colour with "blue" but in a gradient 
> (dark=central, light= as goes higher or lower)
>
>
> pl = data.frame(Time = 0:10, menle = rnorm(11))
>
> pl$menlelb = pl$menle -1
>
> pl$menleub = pl$menle +1
>
> ggplot(pl, aes(Time)) +
>
>   geom_line(aes(y=menle), colour="blue") +
>
>   geom_ribbon(aes(ymin=menlelb, ymax=menleub), fill="blue")
>
>
> Thanks
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to plot a legend centered only on the x axis

2017-05-11 Thread Jim Lemon
Hi Antonio,
First you want the center of the plot:

xylim<-par("usr")
x_center<-sum(xylim[1:2])/2

Then as you want to have you legend above the plot:

# you will probably want to change the "20" to your preference
y_bottom<-xylim[4]+diff(xylim[3:4])/20

then:

legend(x_center,ybottom,...xjust=0.5,yjust=0)

Jim

On Fri, May 12, 2017 at 4:36 AM, Antonio Silva  wrote:
> Hello r-users
>
> I want to plot some barplots inside a looping with the legend placed
> outside the plotting area.
>
> No matter the number of bars I want the legend to be placed centered on the
> x-axis.
>
> See the example below
>
> for(i in 1:10) {
> var_1 <- sample(1000:10,sample(3:8,1))
> ymax <- max(var_1)
> b<-barplot(var_1,col="blue")
> var_2 <- sample(1000:ymax,length(var_1))
> lines(rowSums(b),var_2,type="o",col="red",pch=16)
> par(xpd=TRUE)
> legend(*1.1*
> ,ymax*-0.072,c("var_1","var_2"),horiz=T,cex=1.3,bty="n",pch=c(15,16),col=c("blue","red"),lty=c(0,1),lwd=c(0,2),pt.cex=2)
> readline(prompt="Press [enter] to continue")
> }
>
> What I should use as x position in legend(x,y, ...), instead of *1.1*, to
> have the legend centered on the x-axis?
>
> I would love to use something like legend(x="center",y=ymax*-0.072, ... but
> it did not worked.
>
> I appreciate any suggestions. Best regards.
>
> Antonio
>
> [[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.


  1   2   3   4   5   6   7   8   9   10   >