Re: [R] File conca.

2019-11-05 Thread PIKAL Petr
Hi

in line

> -Original Message-
> From: Val 
> Sent: Wednesday, November 6, 2019 3:24 AM
> To: PIKAL Petr 
> Cc: r-help@R-project.org (r-help@r-project.org) 
> Subject: Re: [R] File conca.
>
> Thank you Petr and Jeff fro your suggestions.
>
> I made some improvement but  still need some tweaking.  I could not get
> correctly the folders names added to each row. Only the last forename was
> added.
> table(Alldata$oldername) resulted
>week2
> 25500
>
> Please see the complete,
>
> 
> folders=c("week1","week2")
> for(i in folders){
>   path=paste("\data\"", i , sep = "")
>   wd <-  setwd(path)
>   Flist = list.files(path,pattern = "^WT")
>   dataA =  lapply(Flist, function(x)read.csv(x, header=T))
>   setwd(wd)
>   temp = do.call("rbind", Alldata)


Shouldn't it be
temp = do.call("rbind", dataA)


This is problematic piece

>   temp$foldername <- i # this seems to be OK

But these in each cycle put recent temp in Alldata and adds temp again by 
rbinding.

>   Alldata <- temp
>   Alldata <- rbind(Alldata, temp)

I understand from your description that you want all data from all files in 
one Alldata object.

You could either read the files from first folder and put them into Alldata 
**before** your cycle.
Alldata <- temp
After you declare Alldata in such way, you could use only

Alldata <- rbind(Alldata, temp)

in your cycle to add data from other folders.

Or you could use some incremental variable to check if it is the first run.

something like

k <- 0

for(i in folders){...
k <- k+1

if (k==1)Alldata <- temp else Alldata <- rbind(Alldata, temp)
...
}

Cheers
Petr

> }
> ###
> Any suggestion please?
>
>
> On Tue, Nov 5, 2019 at 2:13 AM PIKAL Petr  wrote:
> >
> > Hi
> >
> > Help with such operations is rather tricky as only you know exact
> > structrure of your folders.
> >
> > see some hints in line
> >
> > > -Original Message-
> > > From: R-help  On Behalf Of Val
> > > Sent: Tuesday, November 5, 2019 4:33 AM
> > > To: r-help@R-project.org (r-help@r-project.org)
> > > 
> > > Subject: [R] File conca.
> > >
> > > Hi All,
> > >
> > > I have data files in several folders and want combine all  these
> > > files in
> > one
> > > file.  In each folder  there are several files  and these
> > > files have the same structure but different names.   First, in each
> > > folder  I want to concatenate(rbind) all files in to one file. While
> > > I am reading each files and concatenating (rbind) all files, I want
> > > to added
> > the
> > > folder name as one variable  in each row. I am reading the folder
> > > names from a file and for demonstration I am using only two folders
> > > as shown below.
> > > Data\week1 # folder name 1
> > >WT13.csv
> > >WT26.csv   ...
> > >WT10.csv
> > > Data\week2#folder name 2
> > >WT02.csv
> > >WT12.csv
> > >
> > > Below please find  my attempt,
> > >
> > > folders=c("week1","week2")
> > > for(i in folders){
> > >   path=paste("\data\"", i , sep = "")
> > >   setwd(path)
> >
> > you should use
> > wd <- setwd(path)
> >
> > which keeps the original directory for subsequent use
> >
> > >   Flist = list.files(path,pattern = "^WT")
> > >   dataA =  lapply(Flist, function(x)read.csv(x, header=T))
> > >   Alldata = do.call("rbind", dataA) # combine all files
> > >   Alldata$foldername=i  # adding the folder name
> > >
> >
> > now you can do
> >
> > setwd(wd)
> >
> > to return to original directory
> > }
> >
> > > The above works for  for one folder but how can I do it for more
> > > than one folders?
> >
> > You also need to decide if you want all data from all folders in one
> > object called Alldata or if you want several Alldata objects, one for each
> folder.
> >
> > In second case you could use list structure for Alldata. In the first
> > case you could store data from each folder in some temporary object
> > and use rbind directly.
> >
> > something like
> >
> > temp <- do.call("rbind", dataA)
> > temp$foldername <- i
> >
> > Alldata <- temp
> > in the first cycle
> > and
> > Alldata <- rbind(Alldata, temp)
> > in second and all others.
> >
> > Or you could initiate first Alldata manually and use only Alldata <-
> > rbind(Alldata, temp)
> >
> > in your loop.
> >
> > Cheers
> > Petr
> >
> > >
> > > Thank you 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 gu

Re: [R] File conca.

2019-11-05 Thread Val
Thank you Petr and Jeff fro your suggestions.

I made some improvement but  still need some tweaking.  I could not
get correctly the folders names added to each row. Only the last
forename was added.
table(Alldata$oldername) resulted
   week2
25500

Please see the complete,


folders=c("week1","week2")
for(i in folders){
  path=paste("\data\"", i , sep = "")
  wd <-  setwd(path)
  Flist = list.files(path,pattern = "^WT")
  dataA =  lapply(Flist, function(x)read.csv(x, header=T))
  setwd(wd)
  temp = do.call("rbind", Alldata)
  temp$foldername <- i
  Alldata <- temp
  Alldata <- rbind(Alldata, temp)
}
###
Any suggestion please?


On Tue, Nov 5, 2019 at 2:13 AM PIKAL Petr  wrote:
>
> Hi
>
> Help with such operations is rather tricky as only you know exact structrure
> of your folders.
>
> see some hints in line
>
> > -Original Message-
> > From: R-help  On Behalf Of Val
> > Sent: Tuesday, November 5, 2019 4:33 AM
> > To: r-help@R-project.org (r-help@r-project.org) 
> > Subject: [R] File conca.
> >
> > Hi All,
> >
> > I have data files in several folders and want combine all  these files in
> one
> > file.  In each folder  there are several files  and these
> > files have the same structure but different names.   First, in each
> > folder  I want to concatenate(rbind) all files in to one file. While I am
> > reading each files and concatenating (rbind) all files, I want to added
> the
> > folder name as one variable  in each row. I am reading the folder names
> > from a file and for demonstration I am using only two folders  as shown
> > below.
> > Data\week1 # folder name 1
> >WT13.csv
> >WT26.csv   ...
> >WT10.csv
> > Data\week2#folder name 2
> >WT02.csv
> >WT12.csv
> >
> > Below please find  my attempt,
> >
> > folders=c("week1","week2")
> > for(i in folders){
> >   path=paste("\data\"", i , sep = "")
> >   setwd(path)
>
> you should use
> wd <- setwd(path)
>
> which keeps the original directory for subsequent use
>
> >   Flist = list.files(path,pattern = "^WT")
> >   dataA =  lapply(Flist, function(x)read.csv(x, header=T))
> >   Alldata = do.call("rbind", dataA) # combine all files
> >   Alldata$foldername=i  # adding the folder name
> >
>
> now you can do
>
> setwd(wd)
>
> to return to original directory
> }
>
> > The above works for  for one folder but how can I do it for more than one
> > folders?
>
> You also need to decide if you want all data from all folders in one object
> called Alldata or if you want several Alldata objects, one for each folder.
>
> In second case you could use list structure for Alldata. In the first case
> you could store data from each folder in some temporary object and use rbind
> directly.
>
> something like
>
> temp <- do.call("rbind", dataA)
> temp$foldername <- i
>
> Alldata <- temp
> in the first cycle
> and
> Alldata <- rbind(Alldata, temp)
> in second and all others.
>
> Or you could initiate first Alldata manually and use only
> Alldata <- rbind(Alldata, temp)
>
> in your loop.
>
> Cheers
> Petr
>
> >
> > Thank you 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] [FORGED] Re: Help needed for one question (Urgent)

2019-11-05 Thread Wang Jiefei
Agree, especially there is an "Urgent" on the title. He must be too
"urgent" to think about your answer. I will wonder if your effort will be
in vain.

Best,
Jiefei



On Tue, Nov 5, 2019 at 4:52 PM Rolf Turner  wrote:

>
> Richard:  I know that you mean well, but *please* don't do people's
> homework for them!!!  (They are *cheating* by asking R-help to do their
> homework.)
>
> cheers,
>
> Rolf Turner
>
> On 6/11/19 4:27 AM, Richard O'Keefe wrote:
> > This looks vaguely like something from exercism.
> > Let's approach it logically.
> >   xa xb xc ya yb zc
> > We see two patterns here:
> > A:  x x x y y z
> > B: a b c a b c
> > If only we had these two character vectors, we could use
> >   paste(A, B, sep = "")
> > to get the desired result.  So now we have reduced the
> > problem to two simpler subproblems.  We have been given
> > a clue that rep() might be useful.
> > A: rep(c("x", "y", "z"), c(1, 2, 3))
> > B: rep(c("a", "b", "c"), 3)
> > But you were told not to use c().  So now we have three
> > simpler subsubproblems:
> > C: "x" "y" "z"
> > D: 3 2 1
> > E: "a" "b" "c"
> > You were given another hint.  seq().  That builds a vector of numbers.
> > Reading ?seq will give you
> > D: seq(from = 3, to = 1, by = -1)
> > or using ":" syntax,
> > D: 3:1
> >
> > What about C and E?  This needs two more pieces of knowledge:
> > - the variable letters,whose value is c("a","b",...,"y","z")
> > - how vector indexing works in R.
> > E: letters[1:3]
> > C: letters[24:26]
> > So now we can put all the pieces together:
> > paste(rep(letters[24:26], 3:1), rep(letters[1:3], 2), sep = "")
> >
> > You were given
> >   - seq
> >   - rep
> > as hints.  You were expected to look up string handling in R
> > and find things like paste(), substr(), and nchar().
> >
> > What about the variable 'letters'?
> > Well, you were expected to know or find out about substr.
> > You were certainly expected to know about "vectorising".
> > So you would naturally try substr("abc", 1:3, 1:3).
> > And that would not work.
> > So you would be expected to read the documentation:
> > ?substr
> > And then you would find that substr() *doesn't* do what
> > you expect, but substring() *does*.  So
> > C: substring("xyz", 1:3, 1:3)
> > E: substring("abc", 1:3, 1:3)
> >
> > This is not really an exercise in R programming.
> > In real R programming you *don't* avoid arbitrary aspects of the
> > language and library, but use whatever is appropriate.
> > So what *is* this exercise about?
> >
> > (1) It is an exercise in working backwards.  (See the classic book
> > "How to Solve It" by Polya.)  You know what you must construct,
> > you have been given some directions about what to use.  It's
> > about saying "well, I could *finish* this task by doing this action,
> > so what would I have to set up for that?"  In this case, the key
> > step for me was seeing xa xb xc ya yb yc as (x,x,x,y,y,z)++(a,b,c,a,b,c).
> > The mention of rep had me *looking* for repetitions like that.
> >
> > (2) It is an exercise in using the R documentation to figure out how to
> > use rep and seq and what is available for splitting and pasting strings.
> >
> > There is of course no unique answer to this.
> > substring("xaxbxcyaybzc", seq(from=1,to=11,by=2), seq(from=2,to=12,by=2))
> > is another solution.  You didn't say you *had* to use rep.
> >
> > It's not the answer that matters for an exercise like this.
> > It's how you get there.
> >
> >
> >
> >
> >
> > On Tue, 5 Nov 2019 at 23:40, Chandeep Kaur 
> wrote:
> >>
> >> Dear Team,
> >>
> >> Could you please help me with the below question? How can I get the
> desired
> >> output?
> >>
> >> Produce the following sequence using only rep(), seq() and potentially
> >> other functions/operators. You must not use c() nor explicit loops
> >>
> >> “xa” “xb” “xc” “ya” “yb” “zc”
> >>
> >> Thanks & Regards,
> >>
> >> Chandeep Kaur
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] how to place a rug on only the x-axis in a scatterplot with lattice

2019-11-05 Thread Bert Gunter
For the record, I left out a key word in my prior "explanation", which I
have corrected below. I also needed to clarify something, as my original
wording is confusing. Sorry about that.

Bert


On Tue, Nov 5, 2019 at 11:09 AM Bert Gunter  wrote:

> Lattice functions pass down their **unrecognized** arguments to the panel
> function. Once you know this, argument handling is controlled by R's usual
> rules, especially with regard to the "..." argument. Hence, you may wish to
> review tutorials on argument passing in function calls in R.
>
> But briefly, the following may be informative:
>
> xyplot(y ~ foo,
>panel = function(...){## x and y in ... arguments
>  panel.xyplot(...)
>  panel.rug(..., col = "black")
> })
>
> will pass down all the **unrecognized** arguments in the xyplot call
> (there are none here) **plus** the x and y arguments obtained from the
> formula method. Thus panel.rug(...) will get *both* x =  and y = arguments
> and will accordingly put rugs on BOTH axes, as you saw.
>
> To prevent this, you only want to pass down the x argument, not y. Here
> are several ways to do this (check them!):
>
> ## pass down x in ... but pass y explicitly and set it to NULL in
> panel.rug call
> xyplot(y ~ foo,
>panel = function(y,...) { ## x is in ... arguments
>   panel.xyplot(y,..., col = "red")
>   panel.rug(y = NULL,..., col="black")
>})
>
> ## explicitly omit y from the panel.rug call (same as above):
> xyplot(y ~ foo,
>panel = function(y,...) { ## x is in ... arguments
>   panel.xyplot(y,..., col = "red")
>   panel.rug(..., col="black")## y omitted
>})
>
> ## only pass down x explicitly and omit y
> xyplot(y ~ foo,
>panel = function(x,...) {  ## y is in ... arguments
>   panel.xyplot(x,..., col = "red")
>   panel.rug(x, col="black") ## only x argument is passed
>})
>
> Cheers,
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Tue, Nov 5, 2019 at 10:04 AM Christopher W Ryan 
> wrote:
>
>> Thanks Bert. So my lesson here is that I have to "feed" "x" to all my
>> panel functions "upstream" from my panel.rug()?
>>
>> --Chris Ryan
>>
>> On Tue, Nov 5, 2019 at 12:28 PM Bert Gunter 
>> wrote:
>>
>>> Here's how you pass an argument down to the panel function.
>>>
>>> foo <- runif(30,0,5)
>>> y <- rnorm(30, mean = 10)
>>> xyplot(y~foo,
>>>panel = function(x,...) {
>>>   panel.xyplot(x,..., col = "red")
>>>   panel.rug(x, col="black")
>>>})
>>>
>>> Cheers,
>>> Bert
>>>
>>>
>>> Bert Gunter
>>>
>>> "The trouble with having an open mind is that people keep coming along
>>> and sticking things into it."
>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>>
>>>
>>> On Tue, Nov 5, 2019 at 8:41 AM Christopher W Ryan 
>>> wrote:
>>>
 The following produces a scatterplot with rugs on both the vertical and
 horizontal axes.

 library(dplyr)
 library(stringr)
 library(lattice)
 library(latticeExtra)
 ## .
 xyplot(scheduleInterval ~ calledForApptDate, data = dd.2, xlab = "Date
 patient called for appointment", ylab = "Days in the future that patient
 was scheduled",
 panel = function(...) {
 panel.xyplot(..., col = "red")
 panel.smoother(..., span = 0.9, se = FALSE)
 panel.rug(...)
 })

 I'd like a rug to appear only on the horizontal axis.  None of the
 following seem to be the correct syntax:

 panel.rug(..., y = NULL)
 panel.rug(..., y = FALSE)
 panel.rug(x)
 panel.rug(x = ...)

 This does the job:

 xyplot(scheduleInterval ~ calledForApptDate, data = dd.2, xlab = "Date
 patient called for appointment", ylab = "Days in the future that patient
 was scheduled",
 panel = function(...) {
 panel.xyplot(..., col = "red")
 panel.smoother(..., span = 0.9, se = FALSE)
 panel.rug(x = dd.2$calledForApptDate)
 })

 but seems inadvisable. Shouldn't I be making use of ... for passing
 arguments through to the panel.rug() function?  Specifying a variable
 in a
 dataframe by name isn't generalizable.

 Thanks.

 --Chris Ryan

 [[alternative HTML version deleted]]

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

>>>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide ht

Re: [R] [FORGED] Re: Help needed for one question (Urgent)

2019-11-05 Thread Rolf Turner



Richard:  I know that you mean well, but *please* don't do people's 
homework for them!!!  (They are *cheating* by asking R-help to do their 
homework.)


cheers,

Rolf Turner

On 6/11/19 4:27 AM, Richard O'Keefe wrote:

This looks vaguely like something from exercism.
Let's approach it logically.
  xa xb xc ya yb zc
We see two patterns here:
A:  x x x y y z
B: a b c a b c
If only we had these two character vectors, we could use
  paste(A, B, sep = "")
to get the desired result.  So now we have reduced the
problem to two simpler subproblems.  We have been given
a clue that rep() might be useful.
A: rep(c("x", "y", "z"), c(1, 2, 3))
B: rep(c("a", "b", "c"), 3)
But you were told not to use c().  So now we have three
simpler subsubproblems:
C: "x" "y" "z"
D: 3 2 1
E: "a" "b" "c"
You were given another hint.  seq().  That builds a vector of numbers.
Reading ?seq will give you
D: seq(from = 3, to = 1, by = -1)
or using ":" syntax,
D: 3:1

What about C and E?  This needs two more pieces of knowledge:
- the variable letters,whose value is c("a","b",...,"y","z")
- how vector indexing works in R.
E: letters[1:3]
C: letters[24:26]
So now we can put all the pieces together:
paste(rep(letters[24:26], 3:1), rep(letters[1:3], 2), sep = "")

You were given
  - seq
  - rep
as hints.  You were expected to look up string handling in R
and find things like paste(), substr(), and nchar().

What about the variable 'letters'?
Well, you were expected to know or find out about substr.
You were certainly expected to know about "vectorising".
So you would naturally try substr("abc", 1:3, 1:3).
And that would not work.
So you would be expected to read the documentation:
?substr
And then you would find that substr() *doesn't* do what
you expect, but substring() *does*.  So
C: substring("xyz", 1:3, 1:3)
E: substring("abc", 1:3, 1:3)

This is not really an exercise in R programming.
In real R programming you *don't* avoid arbitrary aspects of the
language and library, but use whatever is appropriate.
So what *is* this exercise about?

(1) It is an exercise in working backwards.  (See the classic book
"How to Solve It" by Polya.)  You know what you must construct,
you have been given some directions about what to use.  It's
about saying "well, I could *finish* this task by doing this action,
so what would I have to set up for that?"  In this case, the key
step for me was seeing xa xb xc ya yb yc as (x,x,x,y,y,z)++(a,b,c,a,b,c).
The mention of rep had me *looking* for repetitions like that.

(2) It is an exercise in using the R documentation to figure out how to
use rep and seq and what is available for splitting and pasting strings.

There is of course no unique answer to this.
substring("xaxbxcyaybzc", seq(from=1,to=11,by=2), seq(from=2,to=12,by=2))
is another solution.  You didn't say you *had* to use rep.

It's not the answer that matters for an exercise like this.
It's how you get there.





On Tue, 5 Nov 2019 at 23:40, Chandeep Kaur  wrote:


Dear Team,

Could you please help me with the below question? How can I get the desired
output?

Produce the following sequence using only rep(), seq() and potentially
other functions/operators. You must not use c() nor explicit loops

“xa” “xb” “xc” “ya” “yb” “zc”

Thanks & Regards,

Chandeep Kaur


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Global curve fitting/shared parameters with nls() alternatives

2019-11-05 Thread Bert Gunter
A simplified example of what you wish to do might help to clarify here.

Here's my guess. Feel free to dismiss if I'm off base.

Suppose your model is:
y = exp(a*x) + b

and you wish the b to be constant but the a to vary across expts. Then can
you not combine the data from both into single x, y vectors, add a variable
expt that takes the value 1 for expt1 and 2 for expt 2 and fit the single
model:

y = (expt ==1)*(exp(a1*x) + b)   +  (expt == 2)* (exp(a2*x) + b)

This would obtain separate estimates of a1 and a2 but a single estimate of
b .

There are probably better ways to do this, but I've done hardly any
nonlinear model fitting (so warning!) and can only offer this brute force
approach; so wait for someone to suggest something better before trying it.

Cheers,
Bert


On Tue, Nov 5, 2019 at 9:12 AM James Wagstaff 
wrote:

> Hello
> I am trying to determine least-squares estimates of the parameters of a
> nonlinear model, where I expect some parameters to remain constant across
> experiments, and for others to vary. I believe this is typically referred
> to as global curve fitting, or the presence of shared/nested parameters.
> The "[]" syntax in the stats::nls() function is an extremely convenient
> solution (
>
> https://r.789695.n4.nabble.com/How-to-do-global-curve-fitting-in-R-td4712052.html
> ),
> but in my case I seem to need the Levenberg-Marquardt/Marquardt solvers
> such as nlsr::nlxb() and minpack.lm::nlsLM. I can not find any
> examples/documentation explaining a similar syntax for these tools. Is
> anyone aware of a nls-like tool with this functionality, or an alternative
> approach?
> Best wishes
> James Wagstaff
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] how to place a rug on only the x-axis in a scatterplot with lattice

2019-11-05 Thread Bert Gunter
Here's how you pass an argument down to the panel function.

foo <- runif(30,0,5)
y <- rnorm(30, mean = 10)
xyplot(y~foo,
   panel = function(x,...) {
  panel.xyplot(x,..., col = "red")
  panel.rug(x, col="black")
   })

Cheers,
Bert


Bert Gunter

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


On Tue, Nov 5, 2019 at 8:41 AM Christopher W Ryan 
wrote:

> The following produces a scatterplot with rugs on both the vertical and
> horizontal axes.
>
> library(dplyr)
> library(stringr)
> library(lattice)
> library(latticeExtra)
> ## .
> xyplot(scheduleInterval ~ calledForApptDate, data = dd.2, xlab = "Date
> patient called for appointment", ylab = "Days in the future that patient
> was scheduled",
> panel = function(...) {
> panel.xyplot(..., col = "red")
> panel.smoother(..., span = 0.9, se = FALSE)
> panel.rug(...)
> })
>
> I'd like a rug to appear only on the horizontal axis.  None of the
> following seem to be the correct syntax:
>
> panel.rug(..., y = NULL)
> panel.rug(..., y = FALSE)
> panel.rug(x)
> panel.rug(x = ...)
>
> This does the job:
>
> xyplot(scheduleInterval ~ calledForApptDate, data = dd.2, xlab = "Date
> patient called for appointment", ylab = "Days in the future that patient
> was scheduled",
> panel = function(...) {
> panel.xyplot(..., col = "red")
> panel.smoother(..., span = 0.9, se = FALSE)
> panel.rug(x = dd.2$calledForApptDate)
> })
>
> but seems inadvisable. Shouldn't I be making use of ... for passing
> arguments through to the panel.rug() function?  Specifying a variable in a
> dataframe by name isn't generalizable.
>
> Thanks.
>
> --Chris Ryan
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] (no subject)

2019-11-05 Thread David Winsemius
This question is off-topic for rhelp despite your use of an R package 
because it is a request for advice for statistical issues, rather than 
about R coding. You should read the Posting guide where you are advised 
of this concern. You are also asked to post in plain text and include an 
informative subject line. There are other venues for statistical advice 
such as stats.stackexchange.com and there is also the possibility that 
the package author or maintainer might respond to a polite email.



--

David.

On 11/5/19 4:23 AM, imran damkar wrote:

Greetings,
I have collected the data based on 5 point likert scale(very low, low,
neutral, high,very high) on the factor considered by individual before
making investment decision. There are five factors (D.Vs) Influencing
investment decisions. I am interested in knowing whether there is
significant difference in preference level of male and female(IVs) for the
above said factors.Number of males are 252 and females 98. I have applied
Permutational Manova in adonis function of R, since data are ordinal in
nature, and result is non significant. I have read in literature that
permutation test is non parametric in nature. Does for the permutation test
equality of variance is highly important. Also the computation of mean, S.
D and variance are discouraged by many scholars for ordinal data.
Pls through some light of permutation test and it’s assumption and
violation of it. And if in case PERMANAVO is not suitable for my data then
please suggest appropriate alternative.
Shall be highly obliged.
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] Help needed for one question (Urgent)

2019-11-05 Thread Chandeep Kaur
Dear All,

Thanks for all the support and help and I think I was able to solve my
problem.

Thanks a ton.

Best Regards,
Chandeep Kaur

On Tue, 5 Nov 2019, 8:57 pm Richard O'Keefe,  wrote:

> This looks vaguely like something from exercism.
> Let's approach it logically.
>  xa xb xc ya yb zc
> We see two patterns here:
> A:  x x x y y z
> B: a b c a b c
> If only we had these two character vectors, we could use
>  paste(A, B, sep = "")
> to get the desired result.  So now we have reduced the
> problem to two simpler subproblems.  We have been given
> a clue that rep() might be useful.
> A: rep(c("x", "y", "z"), c(1, 2, 3))
> B: rep(c("a", "b", "c"), 3)
> But you were told not to use c().  So now we have three
> simpler subsubproblems:
> C: "x" "y" "z"
> D: 3 2 1
> E: "a" "b" "c"
> You were given another hint.  seq().  That builds a vector of numbers.
> Reading ?seq will give you
> D: seq(from = 3, to = 1, by = -1)
> or using ":" syntax,
> D: 3:1
>
> What about C and E?  This needs two more pieces of knowledge:
> - the variable letters,whose value is c("a","b",...,"y","z")
> - how vector indexing works in R.
> E: letters[1:3]
> C: letters[24:26]
> So now we can put all the pieces together:
> paste(rep(letters[24:26], 3:1), rep(letters[1:3], 2), sep = "")
>
> You were given
>  - seq
>  - rep
> as hints.  You were expected to look up string handling in R
> and find things like paste(), substr(), and nchar().
>
> What about the variable 'letters'?
> Well, you were expected to know or find out about substr.
> You were certainly expected to know about "vectorising".
> So you would naturally try substr("abc", 1:3, 1:3).
> And that would not work.
> So you would be expected to read the documentation:
> ?substr
> And then you would find that substr() *doesn't* do what
> you expect, but substring() *does*.  So
> C: substring("xyz", 1:3, 1:3)
> E: substring("abc", 1:3, 1:3)
>
> This is not really an exercise in R programming.
> In real R programming you *don't* avoid arbitrary aspects of the
> language and library, but use whatever is appropriate.
> So what *is* this exercise about?
>
> (1) It is an exercise in working backwards.  (See the classic book
> "How to Solve It" by Polya.)  You know what you must construct,
> you have been given some directions about what to use.  It's
> about saying "well, I could *finish* this task by doing this action,
> so what would I have to set up for that?"  In this case, the key
> step for me was seeing xa xb xc ya yb yc as (x,x,x,y,y,z)++(a,b,c,a,b,c).
> The mention of rep had me *looking* for repetitions like that.
>
> (2) It is an exercise in using the R documentation to figure out how to
> use rep and seq and what is available for splitting and pasting strings.
>
> There is of course no unique answer to this.
> substring("xaxbxcyaybzc", seq(from=1,to=11,by=2), seq(from=2,to=12,by=2))
> is another solution.  You didn't say you *had* to use rep.
>
> It's not the answer that matters for an exercise like this.
> It's how you get there.
>
>
>
>
>
> On Tue, 5 Nov 2019 at 23:40, Chandeep Kaur 
> wrote:
> >
> > Dear Team,
> >
> > Could you please help me with the below question? How can I get the
> desired
> > output?
> >
> > Produce the following sequence using only rep(), seq() and potentially
> > other functions/operators. You must not use c() nor explicit loops
> >
> > “xa” “xb” “xc” “ya” “yb” “zc”
> >
> > Thanks & Regards,
> >
> > Chandeep Kaur
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] how to get higher precision p value output

2019-11-05 Thread Eric Berger
> set.seed(1)
> m <- matrix(rnorm(500),ncol=2)
> cor(m)
# [,1]   [,2]
#  [1,] 1. 0.04060113
#  [2,] 0.04060113 1.

> options(digits=12)
> cor(m)
# [,1][,2]
# [1,] 1.0 0.0406011304584
# [2,] 0.0406011304584 1.0

HTH,
Eric


On Tue, Nov 5, 2019 at 7:02 PM Ana Marija 
wrote:

> Hi,
>
> I am running this function:
>
> library(psych)
> corr.test.col.1to3 <- corr.test(allF[1:3], method = "spearman", use =
> "complete.obs")
> names(corr.test.col.1to3)
> corr.test.col.1to3$p
>
> and my result looks like this:
>
> > corr.test.col.1to3$p
>B_NoDB_DwoC B_DwC
> B_NoD  0.000 0.000 1
> B_DwoC 0.000 0.000 1
> B_DwC  0.6501836 0.6501836 0
>
> Does anyone know how to get higher precision for those p values
> instead of 0.000?
>
> I tried:
> corr.test.col.1to3 <- corr.test(allF[1:3], method = "spearman", use =
> "complete.obs",minlength=20)
>
> but it didn't change anything
>
> if I do:
> > str(corr.test.col.1to3)
> List of 11
>  $ r : num [1:3, 1:3] 1 1 0.0139 1 1 ...
>   ..- attr(*, "dimnames")=List of 2
>   .. ..$ : chr [1:3] "B_NoD" "B_DwoC" "B_DwC"
>   .. ..$ : chr [1:3] "B_NoD" "B_DwoC" "B_DwC"
>  $ n : num 1068
>  $ t : num [1:3, 1:3] Inf Inf 0.454 Inf Inf ...
>   ..- attr(*, "dimnames")=List of 2
>   .. ..$ : chr [1:3] "B_NoD" "B_DwoC" "B_DwC"
>   .. ..$ : chr [1:3] "B_NoD" "B_DwoC" "B_DwC"
>  $ p : num [1:3, 1:3] 0 0 0.65 0 0 ...
>   ..- attr(*, "dimnames")=List of 2
>   .. ..$ : chr [1:3] "B_NoD" "B_DwoC" "B_DwC"
>   .. ..$ : chr [1:3] "B_NoD" "B_DwoC" "B_DwC"
>  $ se: num [1:3, 1:3] 0 0 0.0306 0 0 ...
>   ..- attr(*, "dimnames")=List of 2
>   .. ..$ : chr [1:3] "B_NoD" "B_DwoC" "B_DwC"
>   .. ..$ : chr [1:3] "B_NoD" "B_DwoC" "B_DwC"
>  $ sef   : num 0.0306
>  $ adjust: chr "holm"
>  $ sym   : logi TRUE
>  $ ci:'data.frame':3 obs. of  4 variables:
>   ..$ lower: num [1:3] NaN -0.0461 -0.0461
>   ..$ r: num [1:3] 1 0.0139 0.0139
>   ..$ upper: num [1:3] NaN 0.0738 0.0738
>   ..$ p: num [1:3] 0 0.65 0.65
>  $ ci.adj:'data.frame':3 obs. of  2 variables:
>   ..$ lower.adj: num [1:3] NaN -0.0461 -0.0547
>   ..$ upper.adj: num [1:3] NaN 0.0738 0.0824
>  $ Call  : language corr.test(x = allF[1:3], use = "complete.obs",
> method = "spearman")
>  - attr(*, "class")= chr [1:2] "psych" "corr.test"
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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] [R-pkgs] New package 'funprog' : data manipulation with high-order functions

2019-11-05 Thread PY Berrard
DeaR users,

A new package called 'funprog' is now on CRAN : 
https://CRAN.R-project.org/package=funprog

'funprog' contains high-order functions to manipulate data, given one or more 
auxiliary functions.
Functions are inspired by other pure functional programming languages (Haskell 
mainly).

The package also provides built-in function operators for creating compact 
anonymous functions, as well as the possibility to use the purrr package syntax.

If you are interested, you will find more details and examples here : 
https://gitlab.com/py_b/funprog#readme

Best regards,

Pierre-Yves B.

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Global curve fitting/shared parameters with nls() alternatives

2019-11-05 Thread James Wagstaff
Hello
I am trying to determine least-squares estimates of the parameters of a
nonlinear model, where I expect some parameters to remain constant across
experiments, and for others to vary. I believe this is typically referred
to as global curve fitting, or the presence of shared/nested parameters.
The "[]" syntax in the stats::nls() function is an extremely convenient
solution (
https://r.789695.n4.nabble.com/How-to-do-global-curve-fitting-in-R-td4712052.html),
but in my case I seem to need the Levenberg-Marquardt/Marquardt solvers
such as nlsr::nlxb() and minpack.lm::nlsLM. I can not find any
examples/documentation explaining a similar syntax for these tools. Is
anyone aware of a nls-like tool with this functionality, or an alternative
approach?
Best wishes
James Wagstaff

[[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] how to get higher precision p value output

2019-11-05 Thread Ana Marija
Hi,

I am running this function:

library(psych)
corr.test.col.1to3 <- corr.test(allF[1:3], method = "spearman", use =
"complete.obs")
names(corr.test.col.1to3)
corr.test.col.1to3$p

and my result looks like this:

> corr.test.col.1to3$p
   B_NoDB_DwoC B_DwC
B_NoD  0.000 0.000 1
B_DwoC 0.000 0.000 1
B_DwC  0.6501836 0.6501836 0

Does anyone know how to get higher precision for those p values
instead of 0.000?

I tried:
corr.test.col.1to3 <- corr.test(allF[1:3], method = "spearman", use =
"complete.obs",minlength=20)

but it didn't change anything

if I do:
> str(corr.test.col.1to3)
List of 11
 $ r : num [1:3, 1:3] 1 1 0.0139 1 1 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:3] "B_NoD" "B_DwoC" "B_DwC"
  .. ..$ : chr [1:3] "B_NoD" "B_DwoC" "B_DwC"
 $ n : num 1068
 $ t : num [1:3, 1:3] Inf Inf 0.454 Inf Inf ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:3] "B_NoD" "B_DwoC" "B_DwC"
  .. ..$ : chr [1:3] "B_NoD" "B_DwoC" "B_DwC"
 $ p : num [1:3, 1:3] 0 0 0.65 0 0 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:3] "B_NoD" "B_DwoC" "B_DwC"
  .. ..$ : chr [1:3] "B_NoD" "B_DwoC" "B_DwC"
 $ se: num [1:3, 1:3] 0 0 0.0306 0 0 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:3] "B_NoD" "B_DwoC" "B_DwC"
  .. ..$ : chr [1:3] "B_NoD" "B_DwoC" "B_DwC"
 $ sef   : num 0.0306
 $ adjust: chr "holm"
 $ sym   : logi TRUE
 $ ci:'data.frame':3 obs. of  4 variables:
  ..$ lower: num [1:3] NaN -0.0461 -0.0461
  ..$ r: num [1:3] 1 0.0139 0.0139
  ..$ upper: num [1:3] NaN 0.0738 0.0738
  ..$ p: num [1:3] 0 0.65 0.65
 $ ci.adj:'data.frame':3 obs. of  2 variables:
  ..$ lower.adj: num [1:3] NaN -0.0461 -0.0547
  ..$ upper.adj: num [1:3] NaN 0.0738 0.0824
 $ Call  : language corr.test(x = allF[1:3], use = "complete.obs",
method = "spearman")
 - attr(*, "class")= chr [1:2] "psych" "corr.test"

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 merge 3 data frames by rownames?

2019-11-05 Thread Eric Berger
I think your code is a bit buggy. Try this

for(i in 2:length(l)) {
  allF <- merge(allF, l[[i]],  by= "row.names", all.x= F, all.y= F)
  rownames(allF) <- allF$Row.names
  allF <- allF[,-1]
}

HTH,
Eric


On Tue, Nov 5, 2019 at 6:16 PM Ana Marija 
wrote:

> Hi,
>
> I have 3 data frames like this:
>
> > head(s11)
>   B_NoD
> Ebfrl.7uOZfnjp_E7k 7.583709
> ueQUrXd5FH554RlhZc 5.177791
> 0Uu3XrB6Bd14qoNeuc 4.680306
> 0t7nhVLii6tSAxtLhc 4.565023
> fSUyR.vR7Xu0iR4nUU 2.885992
> 0Tm7hdRJxd9zoevPlA 2.866847
> > head(s22)
>  B_DwoC
> Ebfrl.7uOZfnjp_E7k 7.583709
> ueQUrXd5FH554RlhZc 5.177791
> 0Uu3XrB6Bd14qoNeuc 4.680306
> 0t7nhVLii6tSAxtLhc 4.565023
> fSUyR.vR7Xu0iR4nUU 2.885992
> 0Tm7hdRJxd9zoevPlA 2.866847
> > head(s33)
>   B_DwC
> Ebfrl.7uOZfnjp_E7k 7.583709
> ueQUrXd5FH554RlhZc 5.177791
> 0Uu3XrB6Bd14qoNeuc 4.680306
> 0t7nhVLii6tSAxtLhc 4.565023
> fSUyR.vR7Xu0iR4nUU 2.885992
> 0Tm7hdRJxd9zoevPlA 2.866847
>
> I tried merging them using:
>
> rn <- rownames(s11)
> l <- list(s11, s22, s33)
> allF <- l[[1]]
> for(i in 2:length(l)) {
>   dat <- merge(allF, l[[i]],  by= "row.names", all.x= F, all.y= F) [,-1]
>   rownames(allF) <- rn
> }
>
> but my allF has only one column in results, while it would have all 3
> from all 3 data frames:
>
> > head(allF)
>   B_NoD
> Ebfrl.7uOZfnjp_E7k 7.583709
> ueQUrXd5FH554RlhZc 5.177791
> 0Uu3XrB6Bd14qoNeuc 4.680306
> 0t7nhVLii6tSAxtLhc 4.565023
> fSUyR.vR7Xu0iR4nUU 2.885992
> 0Tm7hdRJxd9zoevPlA 2.866847
>
> Please advise,
> Ana
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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] how to place a rug on only the x-axis in a scatterplot with lattice

2019-11-05 Thread Christopher W Ryan
The following produces a scatterplot with rugs on both the vertical and
horizontal axes.

library(dplyr)
library(stringr)
library(lattice)
library(latticeExtra)
## .
xyplot(scheduleInterval ~ calledForApptDate, data = dd.2, xlab = "Date
patient called for appointment", ylab = "Days in the future that patient
was scheduled",
panel = function(...) {
panel.xyplot(..., col = "red")
panel.smoother(..., span = 0.9, se = FALSE)
panel.rug(...)
})

I'd like a rug to appear only on the horizontal axis.  None of the
following seem to be the correct syntax:

panel.rug(..., y = NULL)
panel.rug(..., y = FALSE)
panel.rug(x)
panel.rug(x = ...)

This does the job:

xyplot(scheduleInterval ~ calledForApptDate, data = dd.2, xlab = "Date
patient called for appointment", ylab = "Days in the future that patient
was scheduled",
panel = function(...) {
panel.xyplot(..., col = "red")
panel.smoother(..., span = 0.9, se = FALSE)
panel.rug(x = dd.2$calledForApptDate)
})

but seems inadvisable. Shouldn't I be making use of ... for passing
arguments through to the panel.rug() function?  Specifying a variable in a
dataframe by name isn't generalizable.

Thanks.

--Chris Ryan

[[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] How to merge 3 data frames by rownames?

2019-11-05 Thread Ana Marija
Hi,

I have 3 data frames like this:

> head(s11)
  B_NoD
Ebfrl.7uOZfnjp_E7k 7.583709
ueQUrXd5FH554RlhZc 5.177791
0Uu3XrB6Bd14qoNeuc 4.680306
0t7nhVLii6tSAxtLhc 4.565023
fSUyR.vR7Xu0iR4nUU 2.885992
0Tm7hdRJxd9zoevPlA 2.866847
> head(s22)
 B_DwoC
Ebfrl.7uOZfnjp_E7k 7.583709
ueQUrXd5FH554RlhZc 5.177791
0Uu3XrB6Bd14qoNeuc 4.680306
0t7nhVLii6tSAxtLhc 4.565023
fSUyR.vR7Xu0iR4nUU 2.885992
0Tm7hdRJxd9zoevPlA 2.866847
> head(s33)
  B_DwC
Ebfrl.7uOZfnjp_E7k 7.583709
ueQUrXd5FH554RlhZc 5.177791
0Uu3XrB6Bd14qoNeuc 4.680306
0t7nhVLii6tSAxtLhc 4.565023
fSUyR.vR7Xu0iR4nUU 2.885992
0Tm7hdRJxd9zoevPlA 2.866847

I tried merging them using:

rn <- rownames(s11)
l <- list(s11, s22, s33)
allF <- l[[1]]
for(i in 2:length(l)) {
  dat <- merge(allF, l[[i]],  by= "row.names", all.x= F, all.y= F) [,-1]
  rownames(allF) <- rn
}

but my allF has only one column in results, while it would have all 3
from all 3 data frames:

> head(allF)
  B_NoD
Ebfrl.7uOZfnjp_E7k 7.583709
ueQUrXd5FH554RlhZc 5.177791
0Uu3XrB6Bd14qoNeuc 4.680306
0t7nhVLii6tSAxtLhc 4.565023
fSUyR.vR7Xu0iR4nUU 2.885992
0Tm7hdRJxd9zoevPlA 2.866847

Please advise,
Ana

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] getting summary statistics easily with dplyr

2019-11-05 Thread Christopher W Ryan
I'm trying to modernize my way of thinking, and my coding, into the
dplyr/tidyverse way of doing things.

To get basic summary statistics on a variable in a dataframe, with the
output also being a dataframe. I previously would do something like this,
using other packages:

library(doBy)
doBy.output <- summaryBy(mpg ~ am, data = mtcars, FUN = fivenum)
str(doBy.output)   ## yes, it's a dataframe
## which I would then incorporate into my report via Sweave and latex
latex(doBy.output, file = "")

## Or this:

library(mosaic)
mosaic.output <- favstats(mpg ~ am, data = mtcars)
str(mosaic.output)  ## yes, it's a dataframe
latex(mosaic.output, file = "")


## What would be the "dplyr way" of doing this?  I know I could specify
each summary statistic individually:

library(dplyr)
dplyr.output <- mtcars %>% group_by(am) %>% summarise(min = min(mpg),
 p25 = quantile(mpg, prob = 0.25),
 p50 = median(mpg),
 p75 = quantile(mpg, prob = 0.75),
 max = max(mpg) )
str(dplyr.output)  ## yes, it's a dataframe
latex(dplyr.output, file = "")

## Is there a way to use a single function like fivenum instead of
specifying each desired summary statistic?  dplyr summarise() wants a
result of length 1, not 5

dplyr.output.2 <- mtcars %>% group_by(am) %>% summarise(fivenum(mpg) )

group_map or group_modify seem like they might do the job, but I could
use some guidance on the syntax.


Thanks.

--Chris Ryan

[[alternative HTML version deleted]]

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


Re: [R] Help needed for one question (Urgent)

2019-11-05 Thread Richard O'Keefe
This looks vaguely like something from exercism.
Let's approach it logically.
 xa xb xc ya yb zc
We see two patterns here:
A:  x x x y y z
B: a b c a b c
If only we had these two character vectors, we could use
 paste(A, B, sep = "")
to get the desired result.  So now we have reduced the
problem to two simpler subproblems.  We have been given
a clue that rep() might be useful.
A: rep(c("x", "y", "z"), c(1, 2, 3))
B: rep(c("a", "b", "c"), 3)
But you were told not to use c().  So now we have three
simpler subsubproblems:
C: "x" "y" "z"
D: 3 2 1
E: "a" "b" "c"
You were given another hint.  seq().  That builds a vector of numbers.
Reading ?seq will give you
D: seq(from = 3, to = 1, by = -1)
or using ":" syntax,
D: 3:1

What about C and E?  This needs two more pieces of knowledge:
- the variable letters,whose value is c("a","b",...,"y","z")
- how vector indexing works in R.
E: letters[1:3]
C: letters[24:26]
So now we can put all the pieces together:
paste(rep(letters[24:26], 3:1), rep(letters[1:3], 2), sep = "")

You were given
 - seq
 - rep
as hints.  You were expected to look up string handling in R
and find things like paste(), substr(), and nchar().

What about the variable 'letters'?
Well, you were expected to know or find out about substr.
You were certainly expected to know about "vectorising".
So you would naturally try substr("abc", 1:3, 1:3).
And that would not work.
So you would be expected to read the documentation:
?substr
And then you would find that substr() *doesn't* do what
you expect, but substring() *does*.  So
C: substring("xyz", 1:3, 1:3)
E: substring("abc", 1:3, 1:3)

This is not really an exercise in R programming.
In real R programming you *don't* avoid arbitrary aspects of the
language and library, but use whatever is appropriate.
So what *is* this exercise about?

(1) It is an exercise in working backwards.  (See the classic book
"How to Solve It" by Polya.)  You know what you must construct,
you have been given some directions about what to use.  It's
about saying "well, I could *finish* this task by doing this action,
so what would I have to set up for that?"  In this case, the key
step for me was seeing xa xb xc ya yb yc as (x,x,x,y,y,z)++(a,b,c,a,b,c).
The mention of rep had me *looking* for repetitions like that.

(2) It is an exercise in using the R documentation to figure out how to
use rep and seq and what is available for splitting and pasting strings.

There is of course no unique answer to this.
substring("xaxbxcyaybzc", seq(from=1,to=11,by=2), seq(from=2,to=12,by=2))
is another solution.  You didn't say you *had* to use rep.

It's not the answer that matters for an exercise like this.
It's how you get there.





On Tue, 5 Nov 2019 at 23:40, Chandeep Kaur  wrote:
>
> Dear Team,
>
> Could you please help me with the below question? How can I get the desired
> output?
>
> Produce the following sequence using only rep(), seq() and potentially
> other functions/operators. You must not use c() nor explicit loops
>
> “xa” “xb” “xc” “ya” “yb” “zc”
>
> Thanks & Regards,
>
> Chandeep Kaur
>
> [[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 needed for one question (Urgent)

2019-11-05 Thread Jeff Newmiller
In other words... read the Posting Guide.

On November 5, 2019 2:52:34 AM PST, Jim Lemon  wrote:
>Homework Chandeep, homework.
>
>Jim
>
>On Tue, Nov 5, 2019 at 9:40 PM Chandeep Kaur 
>wrote:
>>
>> Dear Team,
>>
>> Could you please help me with the below question? How can I get the
>desired
>> output?
>>
>> Produce the following sequence using only rep(), seq() and
>potentially
>> other functions/operators. You must not use c() nor explicit loops
>>
>> “xa” “xb” “xc” “ya” “yb” “zc”
>>
>> Thanks & Regards,
>>
>> Chandeep Kaur
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

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

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


[R] (no subject)

2019-11-05 Thread imran damkar
Greetings,
I have collected the data based on 5 point likert scale(very low, low,
neutral, high,very high) on the factor considered by individual before
making investment decision. There are five factors (D.Vs) Influencing
investment decisions. I am interested in knowing whether there is
significant difference in preference level of male and female(IVs) for the
above said factors.Number of males are 252 and females 98. I have applied
Permutational Manova in adonis function of R, since data are ordinal in
nature, and result is non significant. I have read in literature that
permutation test is non parametric in nature. Does for the permutation test
equality of variance is highly important. Also the computation of mean, S.
D and variance are discouraged by many scholars for ordinal data.
Pls through some light of permutation test and it’s assumption and
violation of it. And if in case PERMANAVO is not suitable for my data then
please suggest appropriate alternative.
Shall be highly obliged.
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.


Re: [R] Help needed for one question (Urgent)

2019-11-05 Thread Jim Lemon
Homework Chandeep, homework.

Jim

On Tue, Nov 5, 2019 at 9:40 PM Chandeep Kaur  wrote:
>
> Dear Team,
>
> Could you please help me with the below question? How can I get the desired
> output?
>
> Produce the following sequence using only rep(), seq() and potentially
> other functions/operators. You must not use c() nor explicit loops
>
> “xa” “xb” “xc” “ya” “yb” “zc”
>
> Thanks & Regards,
>
> Chandeep Kaur
>
> [[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 needed for one question (Urgent)

2019-11-05 Thread Chandeep Kaur
Dear Team,

Could you please help me with the below question? How can I get the desired
output?

Produce the following sequence using only rep(), seq() and potentially
other functions/operators. You must not use c() nor explicit loops

“xa” “xb” “xc” “ya” “yb” “zc”

Thanks & Regards,

Chandeep Kaur

[[alternative HTML version deleted]]

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


Re: [R] Order axis by number of entries in lattice plot

2019-11-05 Thread Luigi Marongiu
Thank you. the factor approach worked all right. Thank you for Likert
also: I already used it but here I wanted to run with lattice only.
Best regards

On Mon, Nov 4, 2019 at 6:57 PM Richard M. Heiberger  wrote:
>
> ## The likert function would work well for this example.
> ## Continuing from your example
>
> ## install.packages("HH") ## if necessary
> library(HH)
>
> likert(Family ~ Normal+Tumour+Metastasis, data = df,
>main = "likert, data-order, ReferenceZero=0\nDuplicates your example",
>ReferenceZero=0,
>as.table=FALSE,
>xlab = expression(bold("Number of species")),
>ylab = expression(bold("Families")),
>auto.key = list(space = "top", columns=3),
>col = COLS)
>
> likert(Family ~ Normal+Tumour+Metastasis, data = df,
>main = "likert, positive.order=TRUE, ReferenceZero=0\nThis is
> what you asked for",
>positive.order=TRUE,
>ReferenceZero=0,
>xlab = expression(bold("Number of species")),
>ylab = expression(bold("Families")),
>auto.key = list(space = "top", columns=3),
>col = COLS)
>
> likert(Family ~ Normal+Tumour+Metastasis, data = df,
>main = "likert, positive.order=TRUE, ReferenceZero=1.5\nThis
> puts Normal on left and not-Normal on right",
>positive.order=TRUE,
>ReferenceZero=1.5,
>xlab = expression(bold("Number of species")),
>ylab = expression(bold("Families")),
>auto.key = list(space = "top", columns=3),
>col = COLS)
>
> ## For information on the likert function
> ?likert
>
> ## For more examples
> demo("likert-paper", package="HH")
>
> ## for the paper, open
> http://www.jstatsoft.org/v57/i05/
> ## and click on
> ##   Download PDF
>
> On Mon, Nov 4, 2019 at 8:32 AM Luigi Marongiu  
> wrote:
> >
> > Dear all,
> > I am plotting some values with lattice barchart: the y-axis is
> > automatically ordered alphabetically; is it possible to order the
> > entries by number, so that the 'larger' histograms would be at the top
> > of the plot?
> > This is a working example
> >
> > ```
> > library(lattice)
> > Family = c("Adenoviridae", "Baculoviridae",  "Herpesviridae",   
> > "Mimiviridae",
> > "Myoviridae", "Pandoraviridae",  "Phycodnaviridae", "Podoviridae",
> > "Polydnaviridae",  "Retroviridae", "Siphoviridae","Unassigned")
> > Normal = c(7, 15, 24,  8, 65, 24, 17, 16,  8, 15, 49 , 9)
> > Tumour =c(  17,  75,  94,  14, 242,  28,  41,  69,  12,  11, 305,  51)
> > Metastasis =c(41,  66,  95,   3, 173,  22,  33, 101,  12,  12, 552,  57)
> > df = data.frame(Family, Normal, Tumour, Metastasis, stringsAsFactors = 
> > FALSE)
> > COLS = c("darkolivegreen3", "brown3", "darkorchid3")
> > barchart(Family ~ Normal+Tumour+Metastasis, data = df, stack = TRUE,
> >  xlim=c(1,1000),
> >  main = "Alphabetical order",
> >  xlab = expression(bold("Number of species")),
> >  ylab = expression(bold("Families")),
> >  auto.key = list(space = "top", columns=3),
> >  par.settings = list(superpose.polygon = list(col = COLS)))
> > ```
> >
> >
> > --
> > Best regards,
> > Luigi
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.



-- 
Best regards,
Luigi

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] File conca.

2019-11-05 Thread Jeff Newmiller
I recommend not using setwd unless you have to (e.g at the beginning of a 
script run by cron or another task scheduler). It is much simpler to build 
paths to directories and files using file.path.

On November 5, 2019 12:13:19 AM PST, PIKAL Petr  wrote:
>Hi
>
>Help with such operations is rather tricky as only you know exact
>structrure
>of your folders.
>
>see some hints in line
>
>> -Original Message-
>> From: R-help  On Behalf Of Val
>> Sent: Tuesday, November 5, 2019 4:33 AM
>> To: r-help@R-project.org (r-help@r-project.org)
>
>> Subject: [R] File conca.
>> 
>> Hi All,
>> 
>> I have data files in several folders and want combine all  these
>files in
>one
>> file.  In each folder  there are several files  and these
>> files have the same structure but different names.   First, in each
>> folder  I want to concatenate(rbind) all files in to one file. While
>I am
>> reading each files and concatenating (rbind) all files, I want to
>added
>the
>> folder name as one variable  in each row. I am reading the folder
>names
>> from a file and for demonstration I am using only two folders  as
>shown
>> below.
>> Data\week1 # folder name 1
>>WT13.csv
>>WT26.csv   ...
>>WT10.csv
>> Data\week2#folder name 2
>>WT02.csv
>>WT12.csv
>> 
>> Below please find  my attempt,
>> 
>> folders=c("week1","week2")
>> for(i in folders){
>>   path=paste("\data\"", i , sep = "")
>>   setwd(path)
>
>you should use 
>wd <- setwd(path)
>
>which keeps the original directory for subsequent use
>
>>   Flist = list.files(path,pattern = "^WT")
>>   dataA =  lapply(Flist, function(x)read.csv(x, header=T))
>>   Alldata = do.call("rbind", dataA) # combine all files
>>   Alldata$foldername=i  # adding the folder name
>> 
>
>now you can do
>
>setwd(wd)
>
>to return to original directory
>}
>
>> The above works for  for one folder but how can I do it for more than
>one
>> folders?
>
>You also need to decide if you want all data from all folders in one
>object
>called Alldata or if you want several Alldata objects, one for each
>folder.
>
>In second case you could use list structure for Alldata. In the first
>case
>you could store data from each folder in some temporary object and use
>rbind
>directly.
>
>something like
>
>temp <- do.call("rbind", dataA)
>temp$foldername <- i
>
>Alldata <- temp
>in the first cycle
>and
>Alldata <- rbind(Alldata, temp)
>in second and all others.
>
>Or you could initiate first Alldata manually and use only
>Alldata <- rbind(Alldata, temp)
>
>in your loop.
>
>Cheers
>Petr
>
>> 
>> Thank you 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.

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

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


Re: [R] File conca.

2019-11-05 Thread PIKAL Petr
Hi

Help with such operations is rather tricky as only you know exact structrure
of your folders.

see some hints in line

> -Original Message-
> From: R-help  On Behalf Of Val
> Sent: Tuesday, November 5, 2019 4:33 AM
> To: r-help@R-project.org (r-help@r-project.org) 
> Subject: [R] File conca.
> 
> Hi All,
> 
> I have data files in several folders and want combine all  these files in
one
> file.  In each folder  there are several files  and these
> files have the same structure but different names.   First, in each
> folder  I want to concatenate(rbind) all files in to one file. While I am
> reading each files and concatenating (rbind) all files, I want to added
the
> folder name as one variable  in each row. I am reading the folder names
> from a file and for demonstration I am using only two folders  as shown
> below.
> Data\week1 # folder name 1
>WT13.csv
>WT26.csv   ...
>WT10.csv
> Data\week2#folder name 2
>WT02.csv
>WT12.csv
> 
> Below please find  my attempt,
> 
> folders=c("week1","week2")
> for(i in folders){
>   path=paste("\data\"", i , sep = "")
>   setwd(path)

you should use 
wd <- setwd(path)

which keeps the original directory for subsequent use

>   Flist = list.files(path,pattern = "^WT")
>   dataA =  lapply(Flist, function(x)read.csv(x, header=T))
>   Alldata = do.call("rbind", dataA) # combine all files
>   Alldata$foldername=i  # adding the folder name
> 

now you can do

setwd(wd)

to return to original directory
}

> The above works for  for one folder but how can I do it for more than one
> folders?

You also need to decide if you want all data from all folders in one object
called Alldata or if you want several Alldata objects, one for each folder.

In second case you could use list structure for Alldata. In the first case
you could store data from each folder in some temporary object and use rbind
directly.

something like

temp <- do.call("rbind", dataA)
temp$foldername <- i

Alldata <- temp
in the first cycle
and
Alldata <- rbind(Alldata, temp)
in second and all others.

Or you could initiate first Alldata manually and use only
Alldata <- rbind(Alldata, temp)

in your loop.

Cheers
Petr

> 
> Thank you 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.