Re: [R] Problem with

2012-11-10 Thread Haszun
Thanks for help, now its working.



--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-tp4649082p4649161.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Problem with recursion

2012-11-10 Thread Haszun
I know that maybe it will be stupid question.

What iswrong  with it (i think that i have to do the "stop moment", but i
dont know how)

fibbonacci=function(x) {
while(x>0) {
if (x==1 || x==2) {
return(1)
} else fibbonacci(x-1)+fibbonacci(x-2)
}
}



--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-recursion-tp4649162.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Problem with recursion

2012-11-10 Thread R. Michael Weylandt
On Sat, Nov 10, 2012 at 7:41 AM, Haszun  wrote:
> I know that maybe it will be stupid question.
>
> What iswrong  with it (i think that i have to do the "stop moment", but i
> dont know how)
>
> fibbonacci=function(x) {
> while(x>0) {
> if (x==1 || x==2) {
> return(1)
> } else fibbonacci(x-1)+fibbonacci(x-2)
> }
> }

Just a hint: do you need a while condition? If so, might a return()
help you out? If not, what's the cleanest way to eliminate it? Note
that R has the convention that the final value in the function is the
one returned, but that constructs like this can trip you up:

x <- 5
while(x > 0) x <- x - 1
print(.Last.value)

Cheers,
Michael

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


Re: [R] Labeling position barchart

2012-11-10 Thread Jim Lemon

On 11/09/2012 10:33 PM, Geophagus wrote:

Hi @ all,
I try to set a labeling on simple barchart.
I do it with the text function. I want to see values of the x axis
(BE_AKT$ammo) above the bars.
When I try the following code, the values are shown, but not in the correct
position.
They should be labeled 0.08 above the bars.

text(BE_AKT$ammo, BE_AKT$ammo + 0.08, label = BE_AKT$ammo, family="Calibri")


Hi GeO,
At a rough guess, you want the _bottoms_ of the labels 0.08 user units 
above the tops of the bars. It is very unlikely that the values of 
BE_AKT$ammo (is that the 5.45 or the old 7.62?) will be valid for both x 
and y coordinates. What you probably want to do is collect the x 
positions from the initial plot:


xpos<-barplot(...)

then combine those with the y positions of your values for BE_AKT$ammo:

text(xpos,BE_AKT$ammo + 0.08,label=BE_AKT$ammo,family="Calibri",pos=3)

Notice that "pos=3" argument. This places the text above the 
coordinates. You can also do this with the "adj" argument.


Jim

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


Re: [R] Problem with recursion

2012-11-10 Thread Haszun
Thank you for  help.



--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-recursion-tp4649162p4649166.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] colineraity among categorical variables (multinom)

2012-11-10 Thread Niklas Fischer
Dear all users,

I"d like to ask you how to make decision about colinearity among
categorical independent variables
when the model is multinomial logistic regression.

Any help is appreciated,
Niklas

[[alternative HTML version deleted]]

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


Re: [R] colineraity among categorical variables (multinom)

2012-11-10 Thread Niklas Fischer
Btw, I tried out variance inflation factor(vif)
but it works for glm models(lm) but not multinom or nnet class
Bests,

2012/11/10 Niklas Fischer 

> Dear all users,
>
> I"d like to ask you how to make decision about colinearity among
> categorical independent variables
> when the model is multinomial logistic regression.
>
> Any help is appreciated,
> Niklas
>
>

[[alternative HTML version deleted]]

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


[R] [R-pkgs] package bit64 with new functionality

2012-11-10 Thread Jens Oehlschlägel


Dear R community,

The new version of package 'bit64' - which extends R with fast 64-bit 
integers - now has fast (single-threaded) implementations of the most 
important univariate algorithmic operations (those based on hashing and 
sorting). Package 'bit64' now has methods for 'match', '%in%', 
'duplicated', 'unique', 'table', 'sort', 'order', 'rank', 'quantile', 
'median' and 'summary'. Regarding data management it has novel generics 
'unipos' (positions of the unique values), 'tiepos' (positions of ties), 
'keypos' (positions of values in a sorted unique table) and derived 
methods 'as.factor' and 'as.ordered'. This 64-bit functionality is 
implemented carefully to be not slower than the respective 32-bit 
operations in Base R and also to avoid excessive execution times 
observed with 'order', 'rank' and 'table' (speedup factors 20/16/200 
respective). This increases the dataset size with wich we can work truly 
interactive. The speed is achieved by simple heuristic optimizers: the 
mentioned high-level functions choose the best from multiple low-level 
algorithms and further take advantage of a novel optional caching 
method. In an example R session using a couple of these operations the 
64-bit integers performed 22x faster than base 32-bit integers, 
hash-caching improved this to 24x amortized, sortorder-caching was most 
efficient with 38x (caching both, hashing and sorting is not worth it 
with 32x at duplicated RAM consumption).


Since the package covers the most important functions for (univariate) 
data exploration and data management, I think it is now appropriate to 
claim that R has sound 64-bit integer support, for example for working 
with keys or counts imported from large databases. For details 
concerning approach, implementation and roadmap please check the 
ANNOUNCEMENT-0.9-Details.txt file and the package help files.


Kind regards


Jens Oehlschlägel
Munich, 8.11.2012

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

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


[R] [R-pkgs] Rgraphviz 2.2.1

2012-11-10 Thread Kasper Daniel Hansen
(cross-posted to Graphviz-devel)

Rgraphviz 2.2.1 has been released as part of the Bioconductor 2.11 release.

Rgraphviz is an R interface to the Graphviz library
(www.graphviz.org), which is used for graph
layouts.  Rgraphviz is one of the most popular packages from the
Bioconductor project with more than 39,000 downloads in the last 12
months.

The major, user-visible change in Rgraphviz >= 2.x.x is that Rgraphviz
no longer depends on an externally installed Graphviz.  Instead it is
bundled with a patched version of Graphviz 2.28.0. This should greatly
simplify installation on all platforms (Linux, OS X and Windows, both
32 and 64 bit).  It is now installed as any other Bioconductor
package, simply by:
  R> source("http://www.bioconductor.org/biocLite.R";)
  R> biocLite("Rgraphviz")

In addition, numerous bugfixes to the Rgraphviz code has been incorporated.

This work could not have been completed without the generous help of
numerous people.  In alphabetical order (hopefully including all who
have helped):

>From the Graphviz developers email list
  John Ellson
  Emden R. Gansner
  Stephen North
  Gordon Smith

Help with the R package, extensive testing and building
  Dan Tenenbaum

Help with porting to 64 bit Windows, and for making 64 bit Windows
binaries of Graphviz available.
  Brian D Ripley

Testing and bug reporting
  Claus Bendtsen
  Henrik Bengtsson
  Thomas Cokelaer
  Laurent Gautier
  Anand Gavai
  Klaus K. Holst
  Mike Jiang
  Mikko Korpela
  David Meyer
  Roger D Peng
  Adi Tarca
  Jitao David Zhang

Best,
Kasper Daniel Hansen
Dept. of Biostatistics and Institute of Genetic Medicine
Johns Hopkins University

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

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


Re: [R] Script for searching in a kinship matrix

2012-11-10 Thread ginger
Hi everybody!
I suceeded in extracting the sub-matrix containing just the relevant
subjects of this example data (indeed I could retrieve 190 of the 220
subjects of the data example, so that the relative kinship matrix is a
190X190). For the subjects non present in the kinship matrix case-control
kinship coefficient is to be supposed as 0 (zero) - no relatedness.
I attach this example kinship matrix. KinExample.txt
  



--
View this message in context: 
http://r.789695.n4.nabble.com/Script-for-searching-in-a-kinship-matrix-tp4649089p4649178.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Plot in function

2012-11-10 Thread Pauli
Thanks a lot!



--
View this message in context: 
http://r.789695.n4.nabble.com/Plot-in-function-tp4648576p4649177.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Prediction problem.

2012-11-10 Thread bokaha guy
Dear friends from the R-community,

I am Guy Roger and live in Germany. I am student and user of R. I wanted to do 
some prediction after a linear regression fitting but could´nt because of the 
following message:

> yx<-predict(lm(y~x4+x5),newdata=data.frame(X4,X5))
Warnmeldung:
In predict.lm(lm(y ~ x4 + x5), newdata = data.frame(X4, X5)) :
Vorhersage durch Fit ohne vollen Rang mag täuschen



For your help I thank you in advance.

Friendly greetings

Djipie,bokaha

[[alternative HTML version deleted]]

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


[R] help on date dataset

2012-11-10 Thread anoumou
Hi everybody, 
I am beginer in R and I need your precious help.
I want to create a small function  in R as in sas to retrieve date.
I have a file with data that import in R.
 DATE   PAYS nb_pays.ILI.
1   24/04/2009 usa0
2   24/04/2009 usa0
3   24/04/2009 Mexique0
4   24/04/2009 Mexique0
5   26/04/2009 usa   20
6   26/04/2009 usa   20
7   26/04/2009 usa   20
8   26/04/2009 usa   20
9   26/04/2009 usa   20
10  26/04/2009 Mexique   18
11  27/04/2009 usa   40
12  27/04/2009 Mexique   26
13  27/04/2009  Canada6
14  27/04/2009   Spain1
15  28/04/2009 Canada 6

I want to create something like that:
•   When entering two dates date1,date2 in the fuction extraction.
The result must be: a  new subdata  with one line  per date , per PAYS,per 
nb_pays.ILI (by summing all the number in variable nb_pays.ILI per date,per
country)  and the date must be between date1 and date2.
I sart to do somethings like that
extraction=function(date1,date2)
  {date<-derdata[["DATE"]]
   date
   sort(date)
   PAYS<-derdata[["PAYS"]]
   nb_pays.ILI<-derdata[["nb_pays.ILI."]]
   test1<-as.character(date,"%d %m %y")
   test1
   #the first date
   date1<- "04 03 2009"
   date1 <- strptime(date1, "%d %m %Y")
   date1
   unlist(unclass(date1))
   date1 <- as.POSIXct(date1)
   date1
   attributes(date1)
   date1 <-unclass(date1)
   date1
   
   #the second date
   date2<- "04 12 2009"
   date2 <- strptime(date2, "%d %m %Y")
   date2
   unlist(unclass(date2))
   date2 <- as.POSIXct(date2)
   date2
   attributes(date2)
   date2 <-unclass(date2)
   date2
   B1<- as.POSIXct(test1)
   B1 <-unclass(B1)
   B1
   B4 <- B1[(B1>date1) & (B1http://r.789695.n4.nabble.com/help-on-date-dataset-tp4649175.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Prediction problem.

2012-11-10 Thread David Winsemius

On Nov 10, 2012, at 7:56 AM, bokaha guy wrote:

> Dear friends from the R-community,
> 
> I am Guy Roger and live in Germany. I am student and user of R. I wanted to 
> do some prediction after a linear regression fitting but could´nt because of 
> the following message:
> 
>> yx<-predict(lm(y~x4+x5),newdata=data.frame(X4,X5))
> Warnmeldung:
> In predict.lm(lm(y ~ x4 + x5), newdata = data.frame(X4, X5)) :
> Vorhersage durch Fit ohne vollen Rang mag täuschen

I cannot read the error message, but I will bet dollars to donuts that it has 
to do with the fact that   x4 ist nicht X4

-- 

David Winsemius, MD
Alameda, CA, USA

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


[R] Problem with if

2012-11-10 Thread Haszun
Why it always gives me a 3?

> fun=function(x) {
+ if (x<-3) {
+ return(x) 
+ } else {
+ if(x<2) {
+ return(x^2-1)
+ } else {
+ return(log(x))
+ }}}
> 
> fun(-5)
[1] 3
> fun(0)
[1] 3
> fun(10)
[1] 3
> fun(-10)
[1] 3
> 



--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-if-tp4649180.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] help on date dataset

2012-11-10 Thread arun
HI,
May be this helps:
dat1<-read.table(text="
 DATE   PAYS nb_pays.ILI.
1   24/04/2009 usa    0
2   24/04/2009 usa    0
3   24/04/2009 Mexique    0
4   24/04/2009 Mexique    0
5   26/04/2009 usa   20
6   26/04/2009 usa   20
7   26/04/2009 usa   20
8   26/04/2009 usa   20
9   26/04/2009 usa   20
10  26/04/2009 Mexique   18
11  27/04/2009 usa   40
12  27/04/2009 Mexique   26
13  27/04/2009  Canada    6
14  27/04/2009   Spain    1
15  27/04/2009   Spain    18
16  28/04/2009 Canada 6 
",sep="",header=TRUE,stringsAsFactors=FALSE)

fun1<-function(dat,date1,date2){
date1new<-as.Date(date1,format="%d/%m/%Y")
date2new<-as.Date(date2,format="%d/%m/%Y")
dat[,1]<-as.Date(dat$DATE,format="%d/%m/%Y")
res1<-with(dat,aggregate(nb_pays.ILI.,by=list(DATE,PAYS),sum))
names(res1)<-names(dat)
res2<-res1[res1[,1]>=date1new & res1[,1] <=date2new,]
res2<-res2[order(res2[,1],res2[,2]),]
#res2[,1]<-as.POSIXct(res2[,1])    #if you want to convert to as.POSIXct()
rownames(res2)<-1:nrow(res2)
res2}
date1="24/04/2009"
 date2="27/04/2009"



 fun1(dat1,date1,date2)
#    DATE    PAYS nb_pays.ILI.
#1 2009-04-24 Mexique    0
#2 2009-04-24 usa    0
#3 2009-04-26 Mexique   18
#4 2009-04-26 usa  100
#5 2009-04-27  Canada    6
#6 2009-04-27 Mexique   26
#7 2009-04-27   Spain   19
#8 2009-04-27 usa   40


fun1(dat1,"27/04/2009","28/04/2009")
#    DATE    PAYS nb_pays.ILI.
#1 2009-04-27  Canada    6
#2 2009-04-27 Mexique   26
#3 2009-04-27   Spain   19
#4 2009-04-27 usa   40
#5 2009-04-28  Canada    6


A.K.



- Original Message -
From: anoumou 
To: r-help@r-project.org
Cc: 
Sent: Saturday, November 10, 2012 8:21 AM
Subject: [R] help on date dataset

Hi everybody, 
I am beginer in R and I need your precious help.
I want to create a small function  in R as in sas to retrieve date.
I have a file with data that import in R.
DATE                       PAYS         nb_pays.ILI.
1   24/04/2009                 usa            0
2   24/04/2009                 usa            0
3   24/04/2009             Mexique            0
4   24/04/2009             Mexique            0
5   26/04/2009                 usa           20
6   26/04/2009                 usa           20
7   26/04/2009                 usa           20
8   26/04/2009                 usa           20
9   26/04/2009                 usa           20
10  26/04/2009             Mexique           18
11  27/04/2009                 usa           40
12  27/04/2009             Mexique           26
13  27/04/2009              Canada            6
14  27/04/2009               Spain            1
15  28/04/2009             Canada             6

I want to create something like that:
•    When entering two dates date1,date2 in the fuction extraction.
The result must be: a  new subdata  with one line  per date , per PAYS,per 
nb_pays.ILI (by summing all the number in variable nb_pays.ILI per date,per
country)  and the date must be between date1 and date2.
I sart to do somethings like that
extraction=function(date1,date2)
  {date<-derdata[["DATE"]]
   date
   sort(date)
   PAYS<-derdata[["PAYS"]]
   nb_pays.ILI<-derdata[["nb_pays.ILI."]]
   test1<-as.character(date,"%d %m %y")
   test1
   #the first date
   date1<- "04 03 2009"
   date1 <- strptime(date1, "%d %m %Y")
   date1
   unlist(unclass(date1))
   date1 <- as.POSIXct(date1)
   date1
   attributes(date1)
   date1 <-unclass(date1)
   date1
  
   #the second date
   date2<- "04 12 2009"
   date2 <- strptime(date2, "%d %m %Y")
   date2
   unlist(unclass(date2))
   date2 <- as.POSIXct(date2)
   date2
   attributes(date2)
   date2 <-unclass(date2)
   date2
   B1<- as.POSIXct(test1)
   B1 <-unclass(B1)
   B1
   B4 <- B1[(B1>date1) & (B1http://r.789695.n4.nabble.com/help-on-date-dataset-tp4649175.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] Problem with if

2012-11-10 Thread Haszun
Thank you for help.



--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-if-tp4649180p4649182.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Problem with if

2012-11-10 Thread David Winsemius

On Nov 10, 2012, at 8:34 AM, Haszun wrote:

> Why it always gives me a 3?
> 
>> fun=function(x) {
> + if (x<-3) {

The above code assigns 3 to x.


> + return(x) 
> + } else {
> + if(x<2) {
> + return(x^2-1)
> + } else {
> + return(log(x))
> + }}}
>> 
>> fun(-5)
> [1] 3
>> fun(0)
> [1] 3
>> fun(10)
> [1] 3
>> fun(-10)
> [1] 3
>> 
> 
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Problem-with-if-tp4649180.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
Alameda, CA, USA

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


Re: [R] help on date dataset

2012-11-10 Thread Rui Barradas

Hello,

If I understand it correctly, you have a data.frame whose first column 
is a date and want to extract all lines between two given dates. If so, 
try the following. Note that I've added two new arguments to your function.


dat <- read.table(text="
DATE   PAYS nb_pays.ILI.
1   24/04/2009 usa0
2   24/04/2009 usa0
3   24/04/2009 Mexique0
4   24/04/2009 Mexique0
5   26/04/2009 usa   20
6   26/04/2009 usa   20
7   26/04/2009 usa   20
8   26/04/2009 usa   20
9   26/04/2009 usa   20
10  26/04/2009 Mexique   18
11  27/04/2009 usa   40
12  27/04/2009 Mexique   26
13  27/04/2009  Canada6
14  27/04/2009   Spain1
15  28/04/2009 Canada 6
", header = TRUE)

dat
dat$DATE <- as.Date(dat$DATE, format = "%d/%m/%Y")

extraction <- function(DF, date1, date2, format = "%Y-%m-%d"){
date1 <- as.Date(date1, format)
date2 <- as.Date(date2, format)
idx <- date1 < DF[[1]] & DF[[1]] < date2
DF[idx, ]
}

date1 <- "04 03 2009"
date2 <- "04 12 2009"
extraction(dat, date1, date2, format = "%d %m %Y")


Hope this helps,

Rui Barradas
Em 10-11-2012 13:21, anoumou escreveu:

Hi everybody,
I am beginer in R and I need your precious help.
I want to create a small function  in R as in sas to retrieve date.
I have a file with data that import in R.
  DATE   PAYS nb_pays.ILI.
1   24/04/2009 usa0
2   24/04/2009 usa0
3   24/04/2009 Mexique0
4   24/04/2009 Mexique0
5   26/04/2009 usa   20
6   26/04/2009 usa   20
7   26/04/2009 usa   20
8   26/04/2009 usa   20
9   26/04/2009 usa   20
10  26/04/2009 Mexique   18
11  27/04/2009 usa   40
12  27/04/2009 Mexique   26
13  27/04/2009  Canada6
14  27/04/2009   Spain1
15  28/04/2009 Canada 6

I want to create something like that:
•   When entering two dates date1,date2 in the fuction extraction.
The result must be: a  new subdata  with one line  per date , per PAYS,per
nb_pays.ILI (by summing all the number in variable nb_pays.ILI per date,per
country)  and the date must be between date1 and date2.
I sart to do somethings like that
extraction=function(date1,date2)
   {date<-derdata[["DATE"]]
date
sort(date)
PAYS<-derdata[["PAYS"]]
nb_pays.ILI<-derdata[["nb_pays.ILI."]]
test1<-as.character(date,"%d %m %y")
test1
#the first date
date1<- "04 03 2009"
date1 <- strptime(date1, "%d %m %Y")
date1
unlist(unclass(date1))
date1 <- as.POSIXct(date1)
date1
attributes(date1)
date1 <-unclass(date1)
date1

#the second date

date2<- "04 12 2009"
date2 <- strptime(date2, "%d %m %Y")
date2
unlist(unclass(date2))
date2 <- as.POSIXct(date2)
date2
attributes(date2)
date2 <-unclass(date2)
date2
B1<- as.POSIXct(test1)
B1 <-unclass(B1)
B1
B4 <- B1[(B1>date1) & (B1   
}





--
View this message in context: 
http://r.789695.n4.nabble.com/help-on-date-dataset-tp4649175.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] help on date dataset

2012-11-10 Thread Rui Barradas

Hello,

Sorry, forgot the sum part.

extraction <- function(DF, date1, date2, format = "%Y-%m-%d"){
date1 <- as.Date(date1, format)
date2 <- as.Date(date2, format)
idx <- date1 < DF[[1]] & DF[[1]] < date2
aggregate(DF[idx, 3], DF[idx, 1:2], FUN = sum)
}


Hope this helps,

Rui Barradas
Em 10-11-2012 17:13, Rui Barradas escreveu:

Hello,

If I understand it correctly, you have a data.frame whose first column 
is a date and want to extract all lines between two given dates. If 
so, try the following. Note that I've added two new arguments to your 
function.


dat <- read.table(text="
DATE   PAYS nb_pays.ILI.
1   24/04/2009 usa0
2   24/04/2009 usa0
3   24/04/2009 Mexique0
4   24/04/2009 Mexique0
5   26/04/2009 usa   20
6   26/04/2009 usa   20
7   26/04/2009 usa   20
8   26/04/2009 usa   20
9   26/04/2009 usa   20
10  26/04/2009 Mexique   18
11  27/04/2009 usa   40
12  27/04/2009 Mexique   26
13  27/04/2009  Canada6
14  27/04/2009   Spain1
15  28/04/2009 Canada 6
", header = TRUE)

dat
dat$DATE <- as.Date(dat$DATE, format = "%d/%m/%Y")

extraction <- function(DF, date1, date2, format = "%Y-%m-%d"){
date1 <- as.Date(date1, format)
date2 <- as.Date(date2, format)
idx <- date1 < DF[[1]] & DF[[1]] < date2
DF[idx, ]
}

date1 <- "04 03 2009"
date2 <- "04 12 2009"
extraction(dat, date1, date2, format = "%d %m %Y")


Hope this helps,

Rui Barradas
Em 10-11-2012 13:21, anoumou escreveu:

Hi everybody,
I am beginer in R and I need your precious help.
I want to create a small function  in R as in sas to retrieve date.
I have a file with data that import in R.
  DATE   PAYS nb_pays.ILI.
1   24/04/2009 usa0
2   24/04/2009 usa0
3   24/04/2009 Mexique0
4   24/04/2009 Mexique0
5   26/04/2009 usa   20
6   26/04/2009 usa   20
7   26/04/2009 usa   20
8   26/04/2009 usa   20
9   26/04/2009 usa   20
10  26/04/2009 Mexique   18
11  27/04/2009 usa   40
12  27/04/2009 Mexique   26
13  27/04/2009  Canada6
14  27/04/2009   Spain1
15  28/04/2009 Canada 6

I want to create something like that:
•When entering two dates date1,date2 in the fuction extraction.
The result must be: a  new subdata  with one line  per date , per 
PAYS,per
nb_pays.ILI (by summing all the number in variable nb_pays.ILI per 
date,per

country)  and the date must be between date1 and date2.
I sart to do somethings like that
extraction=function(date1,date2)
   {date<-derdata[["DATE"]]
date
sort(date)
PAYS<-derdata[["PAYS"]]
nb_pays.ILI<-derdata[["nb_pays.ILI."]]
test1<-as.character(date,"%d %m %y")
test1
#the first date
date1<- "04 03 2009"
date1 <- strptime(date1, "%d %m %Y")
date1
unlist(unclass(date1))
date1 <- as.POSIXct(date1)
date1
attributes(date1)
date1 <-unclass(date1)
date1
#the second date
date2<- "04 12 2009"
date2 <- strptime(date2, "%d %m %Y")
date2
unlist(unclass(date2))
date2 <- as.POSIXct(date2)
date2
attributes(date2)
date2 <-unclass(date2)
date2
B1<- as.POSIXct(test1)
B1 <-unclass(B1)
B1
B4 <- B1[(B1>date1) & (B1View this message in context: 
http://r.789695.n4.nabble.com/help-on-date-dataset-tp4649175.html

Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

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


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


Re: [R] Name assignment in for loop

2012-11-10 Thread nrm2010
Thank you, Bert and Peter, for helpful responses.  I'm having a little trouble 
with Bert's approach because writing the lapply function is challenging when 
I'm drawing from two dataframes.  Peter's approach works perfectly, although it 
has less "R" personality.   Wrapping the model statement in  try() keeps it 
running when individual models fail.

Cheers,

Toby

 > 
>lmModels <- vector('list', nrow(dat2)) 
>for (i in 1:nrow(dat2)) 
>{ 
> lmModels[[i]] <- etc 
>} 
> 
>Generally, I add a line after creating the list to name the elements and then 
>address the list using these names as I find that less error prone and more 
>informative. 
> 
>HTH  
> 
>Peter Alspach 
> 
>-Original Message- 
>From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
>Behalf Of nrm2010 
>Sent: Friday, 2 November 2012 10:16 a.m. 
>To: r-help@r-project.org 
>Subject: [R] Name assignment in for loop 
> 
> 
> 
>Dear helpeRs- 
> 
>I'm using a for loop to create a series of models. 
>I'm trying to assign a name to each model created, using the loop index. The 
>loop gets stuck at the name of the model, giving the error "target of 
>assignment expands to non-language object". The linear model runs without 
>error; only the name is problematic. 
> 
>Here is the current loop syntax. The use of dat and dat2 is not an error. I'm 
>pulling data from 2 sources for the model. 
> 
>for (i in 1:dim(dat2)[[1]]) { 
>assign("modelb",i) = dat2$day1[i] & dat$doy <= dat2$day2[i]) dat2$coef[i] <- 
>coef(assign("modelb",i, sep = ""))[[2]] dat2$Rsq[i] <- 
>summary(assign("modelb",i, sep = ""))[[9]] } 
> 
>I have also tried 
>assign("modelb",1:i) #following the ?assign example paste("modelb", i, sep = 
>"") <- (...) assign(paste("modelb", i, sep = "")) <- (...) 
>assign(paste("modelb", i, sep - ""), put linear model here) They all generate 
>the same error message. 
> 
> 
>dim(dat2)[[1]] is 29 
>> dim(dat2)[[1]] 
>[1] 29 
> 
>> class(dim(dat2)[[1]]) 
>[1] "integer" 
> 
>I have not included data because the problem is with the naming syntax; no 
>data are involved except for the number 29. 
> 
>Given this approach, rather than the sapply() approach, what is the correct 
>syntax for naming each model in the sequence? 
> 
>Thank you in advance. 
> 
>Toby Gass 
> 
>__ 
>R-help@r-project.org mailing list 
>https://stat.ethz.ch/mailman/listinfo/r-help 
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
>and provide commented, minimal, self-contained, reproducible code. 
> 
>The contents of this e-mail are confidential and may be subject to legal 
>privilege. 
> If you are not the intended recipient you must not use, disseminate, 
> distribute or 
> reproduce all or any part of this e-mail or attachments. If you have received 
> this 
> e-mail in error, please notify the sender and delete all material pertaining 
> to this 
> e-mail. Any opinion or views expressed in this e-mail are those of the 
> individual 
> sender and may not represent those of The New Zealand Institute for Plant and 
> Food Research Limited. 
>

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


[R] sample mean, variance and SD

2012-11-10 Thread parvez_200207
hi
could you help me to solve this issue

Question:
Using command rweibull(100,8,15), simulate n = 100 realizations from
Weibull(8; 15) distribution. Using the simulated sample, compute the sample
mean, variance and standard deviation of these observations.

I am trying like this

sim<-rweibull(100,8,15) # simulated sample
SM<-mean(sim) # simulated sample mean
var(sim)  # variance
sd(sim)   #SD

Thank you in advance.

Parvez



--
View this message in context: 
http://r.789695.n4.nabble.com/sample-mean-variance-and-SD-tp4649190.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] help on date dataset

2012-11-10 Thread arun
HI Rui,

For some reason, I am not getting the result as expected.
date1
#[1] "24/04/2009"
 date2
#[1] "27/04/2009"

  extraction(dat,date1,date2,format="%Y-%m-%d")
#[1] DATE PAYS x   
#<0 rows> (or 0-length row.names)
#Warning messages:
#1: In extraction(dat, date1, date2, format = "%Y-%m-%d") :
 # Incompatible methods ("Ops.Date", "Ops.factor") for "<"
#2: In extraction(dat, date1, date2, format = "%Y-%m-%d") :
 # Incompatible methods ("Ops.factor", "Ops.Date") for "<"

extraction(dat,"24/04/2009","27/04/2009",format="%Y-%m-%d")
#[1] DATE PAYS x   
#<0 rows> (or 0-length row.names)
#Warning messages:
#1: In extraction(dat, "24/04/2009", "27/04/2009", format = "%Y-%m-%d") :

I tried with my function:
fun1<-function(dat,date1,date2){
date1new<-as.Date(date1,format="%d/%m/%Y")
date2new<-as.Date(date2,format="%d/%m/%Y")
dat[,1]<-as.Date(dat$DATE,format="%d/%m/%Y")
res1<-with(dat,aggregate(nb_pays.ILI.,by=list(DATE,PAYS),sum))
names(res1)<-names(dat)
res2<-res1[res1[,1]>=date1new & res1[,1] <=date2new,]
res2<-res2[order(res2[,1],res2[,2]),]
#res2[,1]<-as.POSIXct(res2[,1])    #if you want to convert to as.POSIXct()
rownames(res2)<-1:nrow(res2)
res2}

 fun1(dat,date1,date2)
#    DATE    PAYS nb_pays.ILI.
#1 2009-04-24 Mexique    0
#2 2009-04-24 usa    0
#3 2009-04-26 Mexique   18
#4 2009-04-26 usa  100
#5 2009-04-27  Canada    6
#6 2009-04-27 Mexique   26
#7 2009-04-27   Spain    1
#8 2009-04-27 usa   40

A.K.




From: Rui Barradas 
To: anoumou 
Cc: r-help@r-project.org
Sent: Saturday, November 10, 2012 12:17 PM
Subject: Re: [R] help on date dataset

Hello,

Sorry, forgot the sum part.

extraction <- function(DF, date1, date2, format = "%Y-%m-%d"){
    date1 <- as.Date(date1, format)
    date2 <- as.Date(date2, format)
    idx <- date1 < DF[[1]] & DF[[1]] < date2
    aggregate(DF[idx, 3], DF[idx, 1:2], FUN = sum)
}


Hope this helps,

Rui Barradas
Em 10-11-2012 17:13, Rui Barradas escreveu:
> Hello,
> 
> If I understand it correctly, you have a data.frame whose first column is a 
> date and want to extract all lines between two given dates. If so, try the 
> following. Note that I've added two new arguments to your function.
> 
> dat <- read.table(text="
> DATE                       PAYS         nb_pays.ILI.
> 1   24/04/2009                 usa            0
> 2   24/04/2009                 usa            0
> 3   24/04/2009             Mexique            0
> 4   24/04/2009             Mexique            0
> 5   26/04/2009                 usa           20
> 6   26/04/2009                 usa           20
> 7   26/04/2009                 usa           20
> 8   26/04/2009                 usa           20
> 9   26/04/2009                 usa           20
> 10  26/04/2009             Mexique           18
> 11  27/04/2009                 usa           40
> 12  27/04/2009             Mexique           26
> 13  27/04/2009              Canada            6
> 14  27/04/2009               Spain            1
> 15  28/04/2009             Canada             6
> ", header = TRUE)
> 
> dat
> dat$DATE <- as.Date(dat$DATE, format = "%d/%m/%Y")
> 
> extraction <- function(DF, date1, date2, format = "%Y-%m-%d"){
>     date1 <- as.Date(date1, format)
>     date2 <- as.Date(date2, format)
>     idx <- date1 < DF[[1]] & DF[[1]] < date2
>     DF[idx, ]
> }
> 
> date1 <- "04 03 2009"
> date2 <- "04 12 2009"
> extraction(dat, date1, date2, format = "%d %m %Y")
> 
> 
> Hope this helps,
> 
> Rui Barradas
> Em 10-11-2012 13:21, anoumou escreveu:
>> Hi everybody,
>> I am beginer in R and I need your precious help.
>> I want to create a small function  in R as in sas to retrieve date.
>> I have a file with data that import in R.
>>   DATE                       PAYS         nb_pays.ILI.
>> 1   24/04/2009                 usa            0
>> 2   24/04/2009                 usa            0
>> 3   24/04/2009             Mexique            0
>> 4   24/04/2009             Mexique            0
>> 5   26/04/2009                 usa           20
>> 6   26/04/2009                 usa           20
>> 7   26/04/2009                 usa           20
>> 8   26/04/2009                 usa           20
>> 9   26/04/2009                 usa           20
>> 10  26/04/2009             Mexique           18
>> 11  27/04/2009                 usa           40
>> 12  27/04/2009             Mexique           26
>> 13  27/04/2009              Canada            6
>> 14  27/04/2009               Spain            1
>> 15  28/04/2009             Canada             6
>> 
>> I want to create something like that:
>> •    When entering two dates date1,date2 in the fuction extraction.
>> The result must be: a  new subdata  with one line  per date , per PAYS,per
>> nb_pays.ILI (by summing all the number in variable nb_pays.ILI per date,per
>> country)  and the date must be between date1 and date2.
>> I sart to do somethings like that
>> extraction=function(date1,date2)
>>    {date<-derdata[["DATE"]]

Re: [R] sample mean, variance and SD

2012-11-10 Thread Sarah Goslee
This is not a homework help list.

On Saturday, November 10, 2012, parvez_200207 wrote:

> hi
> could you help me to solve this issue
>
> Question:
> Using command rweibull(100,8,15), simulate n = 100 realizations from
> Weibull(8; 15) distribution. Using the simulated sample, compute the sample
> mean, variance and standard deviation of these observations.
>
> I am trying like this
>
> sim<-rweibull(100,8,15) # simulated sample
> SM<-mean(sim) # simulated sample mean
> var(sim)  # variance
> sd(sim)   #SD
>
> Thank you in advance.
>
> Parvez
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/sample-mean-variance-and-SD-tp4649190.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org  mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Sarah Goslee
http://www.stringpage.com
http://www.sarahgoslee.com
http://www.functionaldiversity.org

[[alternative HTML version deleted]]

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


Re: [R] help on date dataset

2012-11-10 Thread Rui Barradas

Hello,

Arun, you're using the wrong format, "%Y-%m-%d" is the default, with 
"24/04/2009" you must use


extraction(dat, date1, date2, format = "%d/%m/%Y")
#DATEPAYS   x
#1 2009-04-26 Mexique  18
#2 2009-04-26 usa 100

Rui Barradas

Em 10-11-2012 18:26, arun escreveu:

HI Rui,

For some reason, I am not getting the result as expected.
date1
#[1] "24/04/2009"
  date2
#[1] "27/04/2009"

   extraction(dat,date1,date2,format="%Y-%m-%d")
#[1] DATE PAYS x
#<0 rows> (or 0-length row.names)
#Warning messages:
#1: In extraction(dat, date1, date2, format = "%Y-%m-%d") :
  # Incompatible methods ("Ops.Date", "Ops.factor") for "<"
#2: In extraction(dat, date1, date2, format = "%Y-%m-%d") :
  # Incompatible methods ("Ops.factor", "Ops.Date") for "<"

extraction(dat,"24/04/2009","27/04/2009",format="%Y-%m-%d")
#[1] DATE PAYS x
#<0 rows> (or 0-length row.names)
#Warning messages:
#1: In extraction(dat, "24/04/2009", "27/04/2009", format = "%Y-%m-%d") :

I tried with my function:
fun1<-function(dat,date1,date2){
date1new<-as.Date(date1,format="%d/%m/%Y")
date2new<-as.Date(date2,format="%d/%m/%Y")
dat[,1]<-as.Date(dat$DATE,format="%d/%m/%Y")
res1<-with(dat,aggregate(nb_pays.ILI.,by=list(DATE,PAYS),sum))
names(res1)<-names(dat)
res2<-res1[res1[,1]>=date1new & res1[,1] <=date2new,]
res2<-res2[order(res2[,1],res2[,2]),]
#res2[,1]<-as.POSIXct(res2[,1])#if you want to convert to as.POSIXct()
rownames(res2)<-1:nrow(res2)
res2}

  fun1(dat,date1,date2)
#DATEPAYS nb_pays.ILI.
#1 2009-04-24 Mexique0
#2 2009-04-24 usa0
#3 2009-04-26 Mexique   18
#4 2009-04-26 usa  100
#5 2009-04-27  Canada6
#6 2009-04-27 Mexique   26
#7 2009-04-27   Spain1
#8 2009-04-27 usa   40

A.K.




From: Rui Barradas 
To: anoumou 
Cc: r-help@r-project.org
Sent: Saturday, November 10, 2012 12:17 PM
Subject: Re: [R] help on date dataset

Hello,

Sorry, forgot the sum part.

extraction <- function(DF, date1, date2, format = "%Y-%m-%d"){
 date1 <- as.Date(date1, format)
 date2 <- as.Date(date2, format)
 idx <- date1 < DF[[1]] & DF[[1]] < date2
 aggregate(DF[idx, 3], DF[idx, 1:2], FUN = sum)
}


Hope this helps,

Rui Barradas
Em 10-11-2012 17:13, Rui Barradas escreveu:

Hello,

If I understand it correctly, you have a data.frame whose first column is a 
date and want to extract all lines between two given dates. If so, try the 
following. Note that I've added two new arguments to your function.

dat <- read.table(text="
DATE   PAYS nb_pays.ILI.
1   24/04/2009 usa0
2   24/04/2009 usa0
3   24/04/2009 Mexique0
4   24/04/2009 Mexique0
5   26/04/2009 usa   20
6   26/04/2009 usa   20
7   26/04/2009 usa   20
8   26/04/2009 usa   20
9   26/04/2009 usa   20
10  26/04/2009 Mexique   18
11  27/04/2009 usa   40
12  27/04/2009 Mexique   26
13  27/04/2009  Canada6
14  27/04/2009   Spain1
15  28/04/2009 Canada 6
", header = TRUE)

dat
dat$DATE <- as.Date(dat$DATE, format = "%d/%m/%Y")

extraction <- function(DF, date1, date2, format = "%Y-%m-%d"){
  date1 <- as.Date(date1, format)
  date2 <- as.Date(date2, format)
  idx <- date1 < DF[[1]] & DF[[1]] < date2
  DF[idx, ]
}

date1 <- "04 03 2009"
date2 <- "04 12 2009"
extraction(dat, date1, date2, format = "%d %m %Y")


Hope this helps,

Rui Barradas
Em 10-11-2012 13:21, anoumou escreveu:

Hi everybody,
I am beginer in R and I need your precious help.
I want to create a small function  in R as in sas to retrieve date.
I have a file with data that import in R.
DATE   PAYS nb_pays.ILI.
1   24/04/2009 usa0
2   24/04/2009 usa0
3   24/04/2009 Mexique0
4   24/04/2009 Mexique0
5   26/04/2009 usa   20
6   26/04/2009 usa   20
7   26/04/2009 usa   20
8   26/04/2009 usa   20
9   26/04/2009 usa   20
10  26/04/2009 Mexique   18
11  27/04/2009 usa   40
12  27/04/2009 Mexique   26
13  27/04/2009  Canada6
14  27/04/2009   Spain1
15  28/04/2009 Canada 6

I want to create something like that:
•When entering two dates date1,date2 in the fuction extraction.
The result must be: a  new subdata  with one line  per date , per PAYS,per
nb_pays.ILI (by summing all the number in variable nb_pays.ILI per date,per
country)  and the date 

[R] matrix of all difference between rows values

2012-11-10 Thread cleberchaves
Hello all,
i would like to calculate the difference of all row values and the others
row values from my matrix (table 1). The output (table 2) would be a matrix
with input matrix's row names on row names and colums names, thereby the
difference values among two of the row names could be bether found.

Could someone help me?

Examples:

 Table 1:
 a 10
 b 9
 c 8
 d 7
 e 6


 Table 2:
  a b c d e
 a   0-1-2-3-4
 b   10 -1-2-3
 c21 0-1 -2
 d   32 1  0 1
 e   43 2  1  0



--
View this message in context: 
http://r.789695.n4.nabble.com/matrix-of-all-difference-between-rows-values-tp4649191.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] matrix of all difference between rows values

2012-11-10 Thread cleberchaves
Thank you very much, arun kirshna!

That's it! I only modified the "res1<-apply(toeplitz(dat1[,2]),1,function(x)
10-x)" for "res1<-apply(toeplitz(dat1[,2]),1,function(x) dat1[1,2]-x)" and
worked very well!

Thanks again!



--
View this message in context: 
http://r.789695.n4.nabble.com/matrix-of-all-difference-between-rows-values-tp4649191p4649196.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] help on date dataset

2012-11-10 Thread Rui Barradas

Ok, I've coerced DATE to class Date before running the function:

dat$DATE <- as.Date(dat$DATE, format = "%d/%m/%Y")

Without it the function would be:


extraction <- function(DF, date1, date2, format = "%Y-%m-%d"){
date <- as.Date(DF[[1]], format)
date1 <- as.Date(date1, format)
date2 <- as.Date(date2, format)
idx <- date1 < date & date < date2
aggregate(DF[idx, 3], DF[idx, 1:2], FUN = sum)
}

date1<-"24/04/2009"
date2<-"27/04/2009"
extraction(dat, date1, date2, format = "%d/%m/%Y")
#DATEPAYS   x
#1 26/04/2009 Mexique  18
#2 26/04/2009 usa 100


Note also that the op uses '<' and '>' not'<=' and '>=' so our results 
are different.


Rui Barradas
Em 10-11-2012 19:15, arun escreveu:

Thanks Rui,

I tried that too:
dat <- read.table(text="
DATE   PAYS nb_pays.ILI.
1   24/04/2009 usa0
2   24/04/2009 usa0
3   24/04/2009 Mexique0
4   24/04/2009 Mexique0
5   26/04/2009 usa   20
6   26/04/2009 usa   20
7   26/04/2009 usa   20
8   26/04/2009 usa   20
9   26/04/2009 usa   20
10  26/04/2009 Mexique   18
11  27/04/2009 usa   40
12  27/04/2009 Mexique   26
13  27/04/2009  Canada6
14  27/04/2009   Spain1
15  28/04/2009 Canada 6
", header = TRUE)


extraction <- function(DF, date1, date2, format = "%Y-%m-%d"){
  date1 <- as.Date(date1, format)
  date2 <- as.Date(date2, format)
  idx <- date1 < DF[[1]] & DF[[1]] < date2
  aggregate(DF[idx, 3], DF[idx, 1:2], FUN = sum)
}



extraction(dat,"24/04/2009","26/04/2009", format="%d/%m/%Y")
#Error in aggregate.data.frame(as.data.frame(x), ...) :
  # no rows to aggregate
#In addition: Warning messages:
#1: In extraction(dat, "24/04/2009", "26/04/2009", format = "%d/%m/%Y") :
  # Incompatible methods ("Ops.Date", "Ops.factor") for "<"
#2: In extraction(dat, "24/04/2009", "26/04/2009", format = "%d/%m/%Y") :
  # Incompatible methods ("Ops.factor", "Ops.Date") for "<"

date1<-"24/04/2009"
  date2<-"27/04/2009"

  extraction(dat,"24/04/2009","26/04/2009", format="%d/%m/%Y")
#Error in aggregate.data.frame(as.data.frame(x), ...) :
  # no rows to aggregate
#In addition: Warning messages:
#1: In extraction(dat, "24/04/2009", "26/04/2009", format = "%d/%m/%Y") :
  # Incompatible methods ("Ops.Date", "Ops.factor") for "<"
#2: In extraction(dat, "24/04/2009", "26/04/2009", format = "%d/%m/%Y") :
  # Incompatible methods ("Ops.factor", "Ops.Date") for "<"

  sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
  [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
  [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=C LC_NAME=C
  [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] zoo_1.7-7 stringr_0.6   reshape_0.8.4 plyr_1.7.1

loaded via a namespace (and not attached):
[1] grid_2.15.0lattice_0.20-0 tools_2.15.0



Arun



- Original Message -
From: Rui Barradas 
To: arun 
Cc: R help 
Sent: Saturday, November 10, 2012 1:53 PM
Subject: Re: [R] help on date dataset

Hello,

Arun, you're using the wrong format, "%Y-%m-%d" is the default, with
"24/04/2009" you must use

extraction(dat, date1, date2, format = "%d/%m/%Y")
#DATEPAYS   x
#1 2009-04-26 Mexique  18
#2 2009-04-26 usa 100

Rui Barradas

Em 10-11-2012 18:26, arun escreveu:

HI Rui,

For some reason, I am not getting the result as expected.
date1
#[1] "24/04/2009"
date2
#[1] "27/04/2009"

 extraction(dat,date1,date2,format="%Y-%m-%d")
#[1] DATE PAYS x
#<0 rows> (or 0-length row.names)
#Warning messages:
#1: In extraction(dat, date1, date2, format = "%Y-%m-%d") :
# Incompatible methods ("Ops.Date", "Ops.factor") for "<"
#2: In extraction(dat, date1, date2, format = "%Y-%m-%d") :
# Incompatible methods ("Ops.factor", "Ops.Date") for "<"

extraction(dat,"24/04/2009","27/04/2009",format="%Y-%m-%d")
#[1] DATE PAYS x
#<0 rows> (or 0-length row.names)
#Warning messages:
#1: In extraction(dat, "24/04/2009", "27/04/2009", format = "%Y-%m-%d") :

I tried with my function:
fun1<-function(dat,date1,date2){
date1new<-as.Date(date1,format="%d/%m/%Y")
date2new<-as.Date(date2,format="%d/%m/%Y")
dat[,1]<-as.Date(dat$DATE,format="%d/%m/%Y")
res1<-with(dat,aggregate(nb_pays.ILI.,by=list(DATE,PAYS),sum))
names(res1)<-names(dat)
res2<-res1[res1[,1]>=date1new & res1[,1] <=date2new,]
res2<-res2[order(res2[,1],res2[,2]),]
#res2[,1]<-as.POSIXct(res2[,1])#if you want to convert to as.POSIXct(

Re: [R] matrix of all difference between rows values

2012-11-10 Thread Rui Barradas

Hello,

Try the following.

# Create the dataset
Table1 <- matrix(10:6, ncol = 1)
rownames(Table1) <- letters[1:5]
Table1

t(outer(Table1[,1], Table1[,1], `-`))

Hope this helps,

Rui Barradas
Em 10-11-2012 18:32, cleberchaves escreveu:

Hello all,
i would like to calculate the difference of all row values and the others
row values from my matrix (table 1). The output (table 2) would be a matrix
with input matrix's row names on row names and colums names, thereby the
difference values among two of the row names could be bether found.

Could someone help me?

Examples:

  Table 1:
  a 10
  b 9
  c 8
  d 7
  e 6


  Table 2:
   a b c d e
  a   0-1-2-3-4
  b   10 -1-2-3
  c21 0-1 -2
  d   32 1  0 1
  e   43 2  1  0



--
View this message in context: 
http://r.789695.n4.nabble.com/matrix-of-all-difference-between-rows-values-tp4649191.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] sample mean, variance and SD

2012-11-10 Thread Greg Snow
Your code works for me, can you tell us what output you are getting, what
output you expect to see, and how they differ?


On Sat, Nov 10, 2012 at 11:23 AM, parvez_200207  wrote:

> hi
> could you help me to solve this issue
>
> Question:
> Using command rweibull(100,8,15), simulate n = 100 realizations from
> Weibull(8; 15) distribution. Using the simulated sample, compute the sample
> mean, variance and standard deviation of these observations.
>
> I am trying like this
>
> sim<-rweibull(100,8,15) # simulated sample
> SM<-mean(sim) # simulated sample mean
> var(sim)  # variance
> sd(sim)   #SD
>
> Thank you in advance.
>
> Parvez
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/sample-mean-variance-and-SD-tp4649190.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[alternative HTML version deleted]]

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


[R] vectorized uni-root?

2012-11-10 Thread U30A J C Nash

The package rootoned on http://r-forge.r-project.org/R/?group_id=395
has an all-R version of zeroin (the algorithm of uniroot). This should 
also be in Rmpfr by Martin M., as it was set up for that use. I suspect 
it can be vectorized fairly easily. However, it may be simpler to write, 
or else abstract from that code, a vectorized false position or secant 
code (same formula, FP must have end points with opposite sign function 
values, so is `safer'). This avoids the bisection step and simplifies 
things, but may be a bit less efficient sometimes.


JN



Date: Fri, 9 Nov 2012 14:58:55 +
From: Ravi Varadhan 
To: "'ivo.we...@gmail.com'" 
Cc: "r-help@r-project.org" 
Subject: Re: [R] vectorized uni-root?
Message-ID:
<2f9ea67ef9ae1c48a147cb41be2e15c32e8...@dom-eb-mail1.win.ad.jhu.edu>
Content-Type: text/plain

Hi Ivo,

The only problem is that uniroot() actually uses Brent's algorithm, and 
is based on the C code from netlib (there is also Fortran code available 
- zeroin.f).  Brent's algorithm is more sophisticated than a simple 
bisection approach that you have vectorized.  It combines bisection and 
secant methods along with some quadratic interpolation.  The idea behind 
this hybrid approach (which by the way is a fundamental theme in all of 
numerical analysis) is to get faster convergence while not sacrificing 
the global convergence of bisection.


So, the existing uniroot() will not be deprecated unless you can 
vectorize Brent's hybrid root-finding approach!


Best,
Ravi

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


Re: [R] sample mean, variance and SD

2012-11-10 Thread Greg Snow
This is to all R-helpers (Sarah is just the one that I am replying to),

Have we become a little too draconian on the "not a homework help list"
issue?

Now if someone just states the HW question, gives no indication that they
have done anything to try to solve it themselves, and expects us to give
them a completed answer without effort on their part, I am happy to light
up the flame thrower (and if they are my students they could very well lose
points for poor questions).  But I think there are cases where it is
reasonable for us to help point students in the right direction (at our
own discretion, but without a knee jerk "no homework" response).  Some of
the types of questions that we have seen on this list that I think would
qualify here would include things like:

I already turned in my homework after using  that the
teacher uses, but now I would like to learn how to do it in R as well, can
anyone give me pointers to which help page(s) I should read to learn how to
do .

My teacher says we can use any program we want and I chose R, but the
teacher and TA's don't know R, I have figured out most of this problem
, but I can't figure out how to do
this last part, any pointers?

I fit this model  to the HW data using  and these
are the results that I see , but the answer in the book while
matching on some things has a different value for these coefficients .  I am thinking that R must be using a different
default or encoding than the book, can anyone explain the reason for the
difference or give a pointer to where it is documented?

And other cases where a student is clearly doing homework, but shows that
they have made an effort on their own and is not demanding we do the work
for them, but would rather like a pointer or hint to help them learn
better.  I vote that we adopt a policy (unofficial) that if a student shows
effort and asks a reasonable question that we respond with answers that
will help the student continue to learn (and become a better member of the
R community).  What do others think?


On Sat, Nov 10, 2012 at 11:40 AM, Sarah Goslee wrote:

> This is not a homework help list.
>
> On Saturday, November 10, 2012, parvez_200207 wrote:
>
> > hi
> > could you help me to solve this issue
> >
> > Question:
> > Using command rweibull(100,8,15), simulate n = 100 realizations from
> > Weibull(8; 15) distribution. Using the simulated sample, compute the
> sample
> > mean, variance and standard deviation of these observations.
> >
> > I am trying like this
> >
> > sim<-rweibull(100,8,15) # simulated sample
> > SM<-mean(sim) # simulated sample mean
> > var(sim)  # variance
> > sd(sim)   #SD
> >
> > Thank you in advance.
> >
> > Parvez
> >
> >
> >
> > --
> > View this message in context:
> > http://r.789695.n4.nabble.com/sample-mean-variance-and-SD-tp4649190.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > __
> > R-help@r-project.org  mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>
> --
> Sarah Goslee
> http://www.stringpage.com
> http://www.sarahgoslee.com
> http://www.functionaldiversity.org
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[alternative HTML version deleted]]

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


Re: [R] sample mean, variance and SD

2012-11-10 Thread Berend Hasselman

On 10-11-2012, at 21:09, Greg Snow wrote:

> This is to all R-helpers (Sarah is just the one that I am replying to),
> 
> Have we become a little too draconian on the "not a homework help list"
> issue?

Probably.

> 
> Now if someone just states the HW question, gives no indication that they
> have done anything to try to solve it themselves, and expects us to give
> them a completed answer without effort on their part, I am happy to light
> up the flame thrower (and if they are my students they could very well lose
> points for poor questions).  But I think there are cases where it is
> reasonable for us to help point students in the right direction (at our
> own discretion, but without a knee jerk "no homework" response).  Some of
> the types of questions that we have seen on this list that I think would
> qualify here would include things like:
> 
> I already turned in my homework after using  that the
> teacher uses, but now I would like to learn how to do it in R as well, can
> anyone give me pointers to which help page(s) I should read to learn how to
> do .
> 
> My teacher says we can use any program we want and I chose R, but the
> teacher and TA's don't know R, I have figured out most of this problem
> , but I can't figure out how to do
> this last part, any pointers?
> 
> I fit this model  to the HW data using  and these
> are the results that I see , but the answer in the book while
> matching on some things has a different value for these coefficients  with other numbers>.  I am thinking that R must be using a different
> default or encoding than the book, can anyone explain the reason for the
> difference or give a pointer to where it is documented?
> 
> And other cases where a student is clearly doing homework, but shows that
> they have made an effort on their own and is not demanding we do the work
> for them, but would rather like a pointer or hint to help them learn
> better.  I vote that we adopt a policy (unofficial) that if a student shows
> effort and asks a reasonable question that we respond with answers that
> will help the student continue to learn (and become a better member of the
> R community).  What do others think?
> 

I would tend to agree with the last paragraph.


Berend


> 
> On Sat, Nov 10, 2012 at 11:40 AM, Sarah Goslee wrote:
> 
>> This is not a homework help list.
>> 
>> On Saturday, November 10, 2012, parvez_200207 wrote:
>> 
>>> hi
>>> could you help me to solve this issue
>>> 
>>> Question:
>>> Using command rweibull(100,8,15), simulate n = 100 realizations from
>>> Weibull(8; 15) distribution. Using the simulated sample, compute the
>> sample
>>> mean, variance and standard deviation of these observations.
>>> 
>>> I am trying like this
>>> 
>>> sim<-rweibull(100,8,15) # simulated sample
>>> SM<-mean(sim) # simulated sample mean
>>> var(sim)  # variance
>>> sd(sim)   #SD
>>> 
>>> Thank you in advance.
>>> 
>>> Parvez
>>> 
>>> 
>>> 
>>> --
>>> View this message in context:
>>> http://r.789695.n4.nabble.com/sample-mean-variance-and-SD-tp4649190.html
>>> Sent from the R help mailing list archive at Nabble.com.
>>> 
>>> __
>>> R-help@r-project.org  mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>> 
>> 
>> 
>> --
>> Sarah Goslee
>> http://www.stringpage.com
>> http://www.sarahgoslee.com
>> http://www.functionaldiversity.org
>> 
>>[[alternative HTML version deleted]]
>> 
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>> 
> 
> 
> 
> -- 
> Gregory (Greg) L. Snow Ph.D.
> 538...@gmail.com
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] sample mean, variance and SD

2012-11-10 Thread Berend Hasselman

On 10-11-2012, at 19:23, parvez_200207 wrote:

> hi
> could you help me to solve this issue
> 
> Question:
> Using command rweibull(100,8,15), simulate n = 100 realizations from
> Weibull(8; 15) distribution. Using the simulated sample, compute the sample
> mean, variance and standard deviation of these observations.
> 
> I am trying like this
> 
> sim<-rweibull(100,8,15) # simulated sample
> SM<-mean(sim) # simulated sample mean
> var(sim)  # variance
> sd(sim)   #SD
> 
> Thank you in advance.
> 

What is your actual question?
You have calculated what you were supposed to.

I guessing that the result wasn't what you expected.
I'm not going to give you a ready made answer to a question you didn't ask.
In an R console do

?rweibull 

and read carefully about the shape and scale arguments in the Details section.
That should help you to understand your results.

Berend

> Parvez
> 
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/sample-mean-variance-and-SD-tp4649190.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] sample mean, variance and SD

2012-11-10 Thread Sarah Goslee
I agree with much of what you said. If there is a reasonable effort to have
read the documention or otherwise to have solved the problem on their own,
and a clear question, I will frequently at least give a hint or a pointer
toward a relevant function or two. Also, I wouldn't consider that the first
examples given are homework. I only object to answering questions where the
point of the question is how to do something in R.

The question I replied to today had, well, no actual question. The querent
gets credit for not trying to hide that it was homework, at least, but it
was very clearly an assigned question on how to do something in R, which in
my interpretation is contrary to current list policy.

I will admit a greater willingness to answer well-formed homework questions
that appear on R-help proper, though. I'm sure that's a personal failing.

While I suppose it's not all about me, if the list policy is changed then I
at least won't answer that way.

Sarah

On Saturday, November 10, 2012, Berend Hasselman wrote:

>
> On 10-11-2012, at 21:09, Greg Snow wrote:
>
> > This is to all R-helpers (Sarah is just the one that I am replying to),
> >
> > Have we become a little too draconian on the "not a homework help list"
> > issue?
>
> Probably.
>
> >
> > Now if someone just states the HW question, gives no indication that they
> > have done anything to try to solve it themselves, and expects us to give
> > them a completed answer without effort on their part, I am happy to light
> > up the flame thrower (and if they are my students they could very well
> lose
> > points for poor questions).  But I think there are cases where it is
> > reasonable for us to help point students in the right direction (at our
> > own discretion, but without a knee jerk "no homework" response).  Some of
> > the types of questions that we have seen on this list that I think would
> > qualify here would include things like:
> >
> > I already turned in my homework after using  that
> the
> > teacher uses, but now I would like to learn how to do it in R as well,
> can
> > anyone give me pointers to which help page(s) I should read to learn how
> to
> > do .
> >
> > My teacher says we can use any program we want and I chose R, but the
> > teacher and TA's don't know R, I have figured out most of this problem
> > , but I can't figure out how to
> do
> > this last part, any pointers?
> >
> > I fit this model  to the HW data using  and these
> > are the results that I see , but the answer in the book while
> > matching on some things has a different value for these coefficients
>  > with other numbers>.  I am thinking that R must be using a different
> > default or encoding than the book, can anyone explain the reason for the
> > difference or give a pointer to where it is documented?
> >
> > And other cases where a student is clearly doing homework, but shows that
> > they have made an effort on their own and is not demanding we do the work
> > for them, but would rather like a pointer or hint to help them learn
> > better.  I vote that we adopt a policy (unofficial) that if a student
> shows
> > effort and asks a reasonable question that we respond with answers that
> > will help the student continue to learn (and become a better member of
> the
> > R community).  What do others think?
> >
>
> I would tend to agree with the last paragraph.
>
>
>

-- 
Sarah Goslee
http://www.stringpage.com
http://www.sarahgoslee.com
http://www.functionaldiversity.org

[[alternative HTML version deleted]]

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


Re: [R] sample mean, variance and SD

2012-11-10 Thread Jeff Newmiller
It is not always easy to discern what the instructor wants a student to get out 
of an assignment. Therefore, I can't see changing the policy as it stands.

 That said, it is not always easy to discern homework from self-study, and 
sometimes when the question is well-constructed I don't go out of my way to 
confirm whether it is homework... the instructor has internet access too.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Greg Snow <538...@gmail.com> wrote:

>This is to all R-helpers (Sarah is just the one that I am replying to),
>
>Have we become a little too draconian on the "not a homework help list"
>issue?
>
>Now if someone just states the HW question, gives no indication that
>they
>have done anything to try to solve it themselves, and expects us to
>give
>them a completed answer without effort on their part, I am happy to
>light
>up the flame thrower (and if they are my students they could very well
>lose
>points for poor questions).  But I think there are cases where it is
>reasonable for us to help point students in the right direction (at our
>own discretion, but without a knee jerk "no homework" response).  Some
>of
>the types of questions that we have seen on this list that I think
>would
>qualify here would include things like:
>
>I already turned in my homework after using  that
>the
>teacher uses, but now I would like to learn how to do it in R as well,
>can
>anyone give me pointers to which help page(s) I should read to learn
>how to
>do .
>
>My teacher says we can use any program we want and I chose R, but the
>teacher and TA's don't know R, I have figured out most of this problem
>, but I can't figure out how
>to do
>this last part, any pointers?
>
>I fit this model  to the HW data using  and
>these
>are the results that I see , but the answer in the book while
>matching on some things has a different value for these coefficients
>with other numbers>.  I am thinking that R must be using a different
>default or encoding than the book, can anyone explain the reason for
>the
>difference or give a pointer to where it is documented?
>
>And other cases where a student is clearly doing homework, but shows
>that
>they have made an effort on their own and is not demanding we do the
>work
>for them, but would rather like a pointer or hint to help them learn
>better.  I vote that we adopt a policy (unofficial) that if a student
>shows
>effort and asks a reasonable question that we respond with answers that
>will help the student continue to learn (and become a better member of
>the
>R community).  What do others think?
>
>
>On Sat, Nov 10, 2012 at 11:40 AM, Sarah Goslee
>wrote:
>
>> This is not a homework help list.
>>
>> On Saturday, November 10, 2012, parvez_200207 wrote:
>>
>> > hi
>> > could you help me to solve this issue
>> >
>> > Question:
>> > Using command rweibull(100,8,15), simulate n = 100 realizations
>from
>> > Weibull(8; 15) distribution. Using the simulated sample, compute
>the
>> sample
>> > mean, variance and standard deviation of these observations.
>> >
>> > I am trying like this
>> >
>> > sim<-rweibull(100,8,15) # simulated sample
>> > SM<-mean(sim) # simulated sample mean
>> > var(sim)  # variance
>> > sd(sim)   #SD
>> >
>> > Thank you in advance.
>> >
>> > Parvez
>> >
>> >
>> >
>> > --
>> > View this message in context:
>> >
>http://r.789695.n4.nabble.com/sample-mean-variance-and-SD-tp4649190.html
>> > Sent from the R help mailing list archive at Nabble.com.
>> >
>> > __
>> > R-help@r-project.org  mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> >
>>
>>
>> --
>> Sarah Goslee
>> http://www.stringpage.com
>> http://www.sarahgoslee.com
>> http://www.functionaldiversity.org
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>

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

Re: [R] problem with package development and older defs earlier in search order

2012-11-10 Thread Martin J Reed
Rolf,

Re version control: I use SVN and Git depending on the project I am working on 
and what others are using. Years ago I used RCS, as you say its great for a 
local repository (as is Git). The point I was making was not about version 
control but that others like me might get caught out by saving environments  on 
session quit and those environment having older versions of a function 
definition in it. I appreciate that you can get around this by never saving a 
session (but I suspect I am not the only one that finds saving a session 
useful). 

The point of my "shaganappi" (great, and very apt word!) strategy was:  if you 
are developing code and are debugging with fast change/recompile/test cycles 
then you probably to not want to rebuild the package and load it into R every 
time, it is much quicker to just source the R files and dynload the compiled 
library. It took me a few hours of testing to realise that doing this is a 
problem if you save the session as then when you do get round to producing 
stable code and testing the loading of the package it does not overwrite these 
older versions and is later in the search order. The functions I listed are 
just useful as part of the debugging of package loading for me. Also some of 
the people I shared my earlier (non-packaged) version of the code need to clean 
their saved sessions of the old versions - hence a utility function to do this. 
If you never save a session then clearly this is completely unnecessary, but I 
have a number of users that have saved sessions and need this fix.

I quite understand that doing what I suggested in .onAttach would not be 
acceptable for any production code and I should have made it clearer in my 
email that this was the case - thanks for doing this for other readers. If I do 
submit this to CRAN I would of course not include these functions. I still have 
quite a lot to learn before I would feel confident of doing this anyway…

Thanks again for the helpful comments and guidance on good practice.

Regards,

Martin


On 10 Nov 2012, at 02:50, Rolf Turner  wrote:

> On 10/11/12 12:08, Martin J Reed wrote:
>> Rolf and Duncan
>> 
>> Many thanks. Your answers pointed me to a refinement that is closer to what 
>> I want:
>> 
>>   rm(list=intersect(ls(".GlobalEnv"),ls("package:reedgraph")),
>>  pos=".GlobalEnv")
>> 
>> This only removes items that are "masked" by GlobalEnv from my package.
>> 
>> As this is a bit long for some of the people that need to update their 
>> workspaces I have created a function to fix it:
>> 
>> .update2package  <- function() {
>>   rm(list=intersect(ls(".GlobalEnv"),ls("package:")),
>>  pos=".GlobalEnv")
>> }
>> 
>> Just for completeness (if anyone else reads this). It is possible to make 
>> this happen automatically at package load using
>> 
>> .onAttach <- function(libname, pkgname) { .update2package() }
>> 
>> However, as Duncan says this is REALLY bad practice, but is useful to me 
>> while debugging….
> 
> I really don't see it as being at all useful.  What is the point, in terms of 
> package
> development, of keeping copies of those functions in the global environment if
> you are going to remove them whenever you load the package?
> 
> It sounds to me like you need to implement some system of version control,
> such as subversion (svn).  Personally I use rcs --- simple enough for the 
> simple
> minded such as my very good self to use, and amply adequate for my needs.
> 
> A version control system allows you to "backtrack" if a revision that you make
> to a bit of software turns out to be undesirable.  It will do that much more
> effectively IMHO than your current shaganappi strategy.
> 
> Finally you should note that CRAN policies expressly forbid the sort of thing 
> that you
> propose doing with your .onAttach() function,  should you ever be inclined to 
> submit
> your package to CRAN.
> 
>cheers,
> 
>Rolf

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


[R] Jian-Feng Mao wants to share new pictures with you

2012-11-10 Thread Jian-Feng Mao

   Zoosk

   Hi , Jian-Feng Mao sent you an invite on Zoosk.
   [1]View Invite

   This message was sent by a Zoosk user who entered your email address. If
   you'd prefer not to receive emails when other people send you emails through
   Zoosk, [2]click here

   You have received this message at the email address: [3]r-help@r-project.org

   Copyright © 2007-2012 Zoosk, 989 Market St, San Francisco, CA 94103 USA.

   [4]Privacy Policy

References

   1. 
https://www.zoosk.com/signup/friend?invite-token=11d5b8462e137113262a968fc218ebcb&t_ctr=IN_70_00_en_00_DE_01_M_20121110_21_E&from=find-friends-yes-IN_70_00_en_00_DE_01_M_20121110_21_E
   2. 
https://www.zoosk.com/optout.php?with=r-help%40r-project.org&key=26e2a8a5f74d13a38f85b1894e973bba&from=email_invite
   3. mailto:r-help@r-project.org
   4. http://www.zoosk.com/privacy
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Jian-Feng Mao wants to share new pictures with you

2012-11-10 Thread Jian-Feng Mao

   Zoosk

   Hi , Jian-Feng Mao sent you an invite on Zoosk.
   [1]View Invite

   This message was sent by a Zoosk user who entered your email address. If
   you'd prefer not to receive emails when other people send you emails through
   Zoosk, [2]click here

   You have received this message at the email address: [3]r-help@r-project.org

   Copyright © 2007-2012 Zoosk, 989 Market St, San Francisco, CA 94103 USA.

   [4]Privacy Policy

References

   1. 
https://www.zoosk.com/signup/friend?invite-token=11aa285580170cfb14bc710675d918e8&t_ctr=IN_70_00_en_00_DE_01_M_20121110_21_E&from=find-friends-yes-IN_70_00_en_00_DE_01_M_20121110_21_E
   2. 
https://www.zoosk.com/optout.php?with=r-help%40r-project.org&key=26e2a8a5f74d13a38f85b1894e973bba&from=email_invite
   3. mailto:r-help@r-project.org
   4. http://www.zoosk.com/privacy
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Likelihood ratio

2012-11-10 Thread bgnumis bgnum
Hi All


I have to run multiple  stimations and to compute Likelihhod ratio.

If I compute ls function with coef and summary I can extract "outputs" that
I need.

I am not able to find something similar to log liklihood

Can you pease tell me running a ls function x on y how to extract if
posible LR statitic or Likelihood or Log likelihood.

Many thanks in advance. If you send me some manual or webpage guide I will
be very happy.

I will try to improve my posts and questions.

[[alternative HTML version deleted]]

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


Re: [R] help on date dataset

2012-11-10 Thread arun
Thanks, Rui,

Got it right:
 extraction(dat,date1,date2,format="%d/%m/%Y")
#    DATE    PAYS   x
#1 26/04/2009 Mexique  18
#2 26/04/2009 usa 100


A.K.



- Original Message -
From: Rui Barradas 
To: arun ; r-help 
Cc: 
Sent: Saturday, November 10, 2012 2:33 PM
Subject: Re: [R] help on date dataset

Ok, I've coerced DATE to class Date before running the function:

dat$DATE <- as.Date(dat$DATE, format = "%d/%m/%Y")

Without it the function would be:


extraction <- function(DF, date1, date2, format = "%Y-%m-%d"){
     date <- as.Date(DF[[1]], format)
     date1 <- as.Date(date1, format)
     date2 <- as.Date(date2, format)
     idx <- date1 < date & date < date2
     aggregate(DF[idx, 3], DF[idx, 1:2], FUN = sum)
}

date1<-"24/04/2009"
date2<-"27/04/2009"
extraction(dat, date1, date2, format = "%d/%m/%Y")
#        DATE    PAYS   x
#1 26/04/2009 Mexique  18
#2 26/04/2009     usa 100


Note also that the op uses '<' and '>' not'<=' and '>=' so our results 
are different.

Rui Barradas
Em 10-11-2012 19:15, arun escreveu:
> Thanks Rui,
>
> I tried that too:
> dat <- read.table(text="
> DATE                       PAYS         nb_pays.ILI.
> 1   24/04/2009                 usa            0
> 2   24/04/2009                 usa            0
> 3   24/04/2009             Mexique            0
> 4   24/04/2009             Mexique            0
> 5   26/04/2009                 usa           20
> 6   26/04/2009                 usa           20
> 7   26/04/2009                 usa           20
> 8   26/04/2009                 usa           20
> 9   26/04/2009                 usa           20
> 10  26/04/2009             Mexique           18
> 11  27/04/2009                 usa           40
> 12  27/04/2009             Mexique           26
> 13  27/04/2009              Canada            6
> 14  27/04/2009               Spain            1
> 15  28/04/2009             Canada             6
> ", header = TRUE)
>
>
> extraction <- function(DF, date1, date2, format = "%Y-%m-%d"){
>       date1 <- as.Date(date1, format)
>       date2 <- as.Date(date2, format)
>       idx <- date1 < DF[[1]] & DF[[1]] < date2
>       aggregate(DF[idx, 3], DF[idx, 1:2], FUN = sum)
> }
>
>
>
> extraction(dat,"24/04/2009","26/04/2009", format="%d/%m/%Y")
> #Error in aggregate.data.frame(as.data.frame(x), ...) :
>   # no rows to aggregate
> #In addition: Warning messages:
> #1: In extraction(dat, "24/04/2009", "26/04/2009", format = "%d/%m/%Y") :
>   # Incompatible methods ("Ops.Date", "Ops.factor") for "<"
> #2: In extraction(dat, "24/04/2009", "26/04/2009", format = "%d/%m/%Y") :
>   # Incompatible methods ("Ops.factor", "Ops.Date") for "<"
>
> date1<-"24/04/2009"
>   date2<-"27/04/2009"
>
>   extraction(dat,"24/04/2009","26/04/2009", format="%d/%m/%Y")
> #Error in aggregate.data.frame(as.data.frame(x), ...) :
>   # no rows to aggregate
> #In addition: Warning messages:
> #1: In extraction(dat, "24/04/2009", "26/04/2009", format = "%d/%m/%Y") :
>   # Incompatible methods ("Ops.Date", "Ops.factor") for "<"
> #2: In extraction(dat, "24/04/2009", "26/04/2009", format = "%d/%m/%Y") :
>   # Incompatible methods ("Ops.factor", "Ops.Date") for "<"
>
>   sessionInfo()
> R version 2.15.0 (2012-03-30)
> Platform: x86_64-pc-linux-gnu (64-bit)
>
> locale:
>   [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
>   [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
>   [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
>   [7] LC_PAPER=C                 LC_NAME=C
>   [9] LC_ADDRESS=C               LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] zoo_1.7-7     stringr_0.6   reshape_0.8.4 plyr_1.7.1
>
> loaded via a namespace (and not attached):
> [1] grid_2.15.0    lattice_0.20-0 tools_2.15.0
>
>
>
> Arun
>
>
>
> - Original Message -
> From: Rui Barradas 
> To: arun 
> Cc: R help 
> Sent: Saturday, November 10, 2012 1:53 PM
> Subject: Re: [R] help on date dataset
>
> Hello,
>
> Arun, you're using the wrong format, "%Y-%m-%d" is the default, with
> "24/04/2009" you must use
>
> extraction(dat, date1, date2, format = "%d/%m/%Y")
> #        DATE    PAYS   x
> #1 2009-04-26 Mexique  18
> #2 2009-04-26     usa 100
>
> Rui Barradas
>
> Em 10-11-2012 18:26, arun escreveu:
>> HI Rui,
>>
>> For some reason, I am not getting the result as expected.
>> date1
>> #[1] "24/04/2009"
>>     date2
>> #[1] "27/04/2009"
>>
>>      extraction(dat,date1,date2,format="%Y-%m-%d")
>> #[1] DATE PAYS x
>> #<0 rows> (or 0-length row.names)
>> #Warning messages:
>> #1: In extraction(dat, date1, date2, format = "%Y-%m-%d") :
>>     # Incompatible methods ("Ops.Date", "Ops.factor") for "<"
>> #2: In extraction(dat, date1, date2, format = "%Y-%m-%d") :
>>     # Incompatible methods ("Ops.factor", "Ops.Date") for "<"
>>
>> extraction(dat,"24/04/2009","27/04/2009",format="%Y-%m-%d")
>> #[1] DATE PAYS x
>> #<0 rows> (or 0-len

Re: [R] matrix of all difference between rows values

2012-11-10 Thread cleberchaves
Mmmm...

Actually, Rui Barradas is the right!

Arun kirshna, yours script has an error. That repeat the same set of numbers
in all columns...

Anyway, thanks for both!



--
View this message in context: 
http://r.789695.n4.nabble.com/matrix-of-all-difference-between-rows-values-tp4649191p4649207.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] help on date dataset

2012-11-10 Thread anoumou

Rui  and ,arun thanks you so much.
as i am a beginner, i am on that subject since two days.
Thanks,thanks so much.
It works !!! 



--
View this message in context: 
http://r.789695.n4.nabble.com/help-on-date-dataset-tp4649175p4649203.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] matrix of all difference between rows values

2012-11-10 Thread arun
HI,
No problem.

You can also use ?aaply() from library(plyr)
dat1<-read.table(text="
 a 10
 b 9
 c 8
 d 7
 e 6
",sep="",header=FALSE,stringsAsFactors=FALSE)
library(plyr) 

res1<-aaply(dat1[1,2],1,"-",toeplitz(dat1[,2]))
 res1[upper.tri(res1)]<- -1*res1[upper.tri(res1)] 
rownames(res1)<-colnames(res1)<-dat1[,1] 
 res1
   
#    a  b  c  d  e
 # a 0 -1 -2 -3 -4
 # b 1  0 -1 -2 -3
  #c 2  1  0 -1 -2
  #d 3  2  1  0 -1
  #e 4  3  2  1  0

#or

res2<-matrix(mapply("-",dat1[1,2],toeplitz(dat1[,2])),ncol=5)
#or
#res2<- matrix(sapply(toeplitz(dat1[,2]),function(x) dat1[1,2]-x),ncol=5)
res2[upper.tri(res2)]<- -1*res2[upper.tri(res2)]
dimnames(res2)<-dimnames(res1)
identical(res2,res1)
#[1] TRUE
A.K.



- Original Message -
From: cleberchaves 
To: r-help@r-project.org
Cc: 
Sent: Saturday, November 10, 2012 2:25 PM
Subject: Re: [R] matrix of all difference between rows values

Thank you very much, arun kirshna!

That's it! I only modified the "res1<-apply(toeplitz(dat1[,2]),1,function(x)
10-x)" for "res1<-apply(toeplitz(dat1[,2]),1,function(x) dat1[1,2]-x)" and
worked very well!

Thanks again!



--
View this message in context: 
http://r.789695.n4.nabble.com/matrix-of-all-difference-between-rows-values-tp4649191p4649196.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] test for a condition in a vector for loop not working

2012-11-10 Thread scoyoc
Once again, thanks!
MVS



-
MVS
=
Matthew Van Scoyoc
Graduate Research Assistant, Ecology
Wildland Resources Department & Ecology Center
Quinney College of Natural Resources
Utah State University
Logan, UT
=
Think SNOW!


--
View this message in context: 
http://r.789695.n4.nabble.com/test-for-a-condition-in-a-vector-for-loop-not-working-tp4649212p4649216.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Likelihood ratio

2012-11-10 Thread David Winsemius

On Nov 10, 2012, at 11:57 AM, bgnumis bgnum wrote:

> Hi All
> 
> 
> I have to run multiple  stimations and to compute Likelihhod ratio.
> 
> If I compute ls function with coef and summary I can extract "outputs" that
> I need.

Do you mean "lm"?

> 
> I am not able to find something similar to log liklihood

You can use glm' with family="gaussian". Deviance is -2*LL


> 
> Can you pease tell me running a ls function x on y how to extract if
> posible LR statitic or Likelihood or Log likelihood.

Of you can look at the code and  see how it does it.

> Many thanks in advance. If you send me some manual or webpage guide I will
> be very happy.

Please read the Posting Guide. There are many helpful ideas about how to get 
further information and avoid the appearance of cluelessness.

-- 

David Winsemius, MD
Alameda, CA, USA

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


[R] help with for loop to test for a condition in a vector

2012-11-10 Thread scoyoc
I want my for loop to test for the presence of a term in a vector and return
a value to a new vector. I'm not writing it correctly though. Here's what I
have...

> testfor = letters[1:5]
> x = c("a", "b", "e", "f", "g")
> result = rep(NA, length(testfor))
> 
> for (i in testfor){
+   v = any(x == testfor[i])
+   result[i] = v
+ }
> 
> result
a  b  c  d  e 
NA NA NA NA NA NA NA NA NA NA 

I would like to get

>result
TRUE TRUE TRUE FALSE FALSE

Thanks,
MVS



-
MVS
=
Matthew Van Scoyoc
Graduate Research Assistant, Ecology
Wildland Resources Department & Ecology Center
Quinney College of Natural Resources
Utah State University
Logan, UT
=
Think SNOW!


--
View this message in context: 
http://r.789695.n4.nabble.com/help-with-for-loop-to-test-for-a-condition-in-a-vector-tp4649213.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] For loop question

2012-11-10 Thread dae
I have this code:
IEF <- to.monthly(IEF, indexAt="endof")
SPY <- to.monthly(SPY, indexAt="endof")

I would like to use a for loop instead of separate entries,
so the only code that needs to be modified is the list
of symbols.

symbols <- c("IEF", "SPY")
for(symbol in symbols) {
  symbol <- to.monthly(symbol, indexAt="endof")
}
This for loop doesn't work. It puts each output into  
*symbol *not into *IEF *and *SPY*.
How do I put the output into the existing objects using
a for loop?

Note: to.monthly() is an xts function



--
View this message in context: 
http://r.789695.n4.nabble.com/For-loop-question-tp4649215.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] help with for loop to test for a condition in a vector

2012-11-10 Thread David Winsemius

On Nov 10, 2012, at 2:07 PM, scoyoc wrote:

> I want my for loop to test for the presence of a term in a vector and return
> a value to a new vector. I'm not writing it correctly though. Here's what I
> have...
> 
>> testfor = letters[1:5]
>> x = c("a", "b", "e", "f", "g")
>> result = rep(NA, length(testfor))
>> 
>> for (i in testfor){
> +   v = any(x == testfor[i])
> +   result[i] = v
> + }
>> 
>> result
>a  b  c  d  e 
> NA NA NA NA NA NA NA NA NA NA 
> 
> I would like to get
> 
>> result
> TRUE TRUE TRUE FALSE FALSE
> 
Looks like yu want the first of these:


> x %in% testfor
[1]  TRUE  TRUE  TRUE FALSE FALSE

> testfor %in% x
[1]  TRUE  TRUE FALSE FALSE  TRUE 

-- 

David Winsemius, MD
Alameda, CA, USA

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


Re: [R] For loop question

2012-11-10 Thread David Winsemius

On Nov 10, 2012, at 2:36 PM, dae wrote:

> I have this code:
> IEF <- to.monthly(IEF, indexAt="endof")
> SPY <- to.monthly(SPY, indexAt="endof")
> 
> I would like to use a for loop instead of separate entries,
> so the only code that needs to be modified is the list
> of symbols.
> 
> symbols <- c("IEF", "SPY")
> for(symbol in symbols) {
>  symbol <- to.monthly(symbol, indexAt="endof")
> }
> This for loop doesn't work. It puts each output into  
> *symbol *not into *IEF *and *SPY*.
> How do I put the output into the existing objects using
> a for loop?

http://127.0.0.1:21620/doc/manual/R-FAQ.html#How-can-I-turn-a-string-into-a-variable_003f

OOOPs. That link is the one to my own private version of the FAQ. You, of 
course, have one on your machine since it comes with every default 
installation, or you can get the one oneCRAN from Google with a search on : R 
FAQ.

> 
> Note: to.monthly() is an xts function
> 

-- 

David Winsemius, MD
Alameda, CA, USA

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


Re: [R] matrix of all difference between rows values

2012-11-10 Thread arun
Hi,

Though the results from Rui, and me are similar, may be it differs in other 
instances.

My result: 
dat1<-read.table(text="
 a 10
 b 9
 c 8
 d 7
 e 6
",sep="",header=FALSE,stringsAsFactors=FALSE)
 res1<-apply(toeplitz(dat1[,2]),1,function(x) 10-x)
res1[upper.tri(res1)]<- -1*res1[upper.tri(res1)]
row.names(res1)<-dat1[,1]
 colnames(res1)<-dat1[,1]
 res1 
#  a  b  c  d  e 
#a 0 -1 -2 -3 -4 
#b 1  0 -1 -2 -3 
#c 2  1  0 -1 -2 
#d 3  2  1  0 -1 
#e 4  3  2  1  0 

Rui's solution: 
 t(outer(Table1[,1],Table1[,1],"-")) 
#  a  b  c  d  e 
#a 0 -1 -2 -3 -4 
#b 1  0 -1 -2 -3 
#c 2  1  0 -1 -2 
#d 3  2  1  0 -1 
#e 4  3  2  1  0 


I guess ?expand.grid() might also help you.
dat2<-expand.grid(dat1[,2],dat1[,2])
mat1<-matrix(apply(dat2,1,diff),ncol=5)
dimnames(mat1)<-dimnames(res1)
 mat1
#  a  b  c  d  e
#a 0 -1 -2 -3 -4
#b 1  0 -1 -2 -3
#c 2  1  0 -1 -2
#d 3  2  1  0 -1
#e 4  3  2  1  0


A.K.




- Original Message -
From: cleberchaves 
To: r-help@r-project.org
Cc: 
Sent: Saturday, November 10, 2012 3:55 PM
Subject: Re: [R] matrix of all difference between rows values

Mmmm...

Actually, Rui Barradas is the right!

Arun kirshna, yours script has an error. That repeat the same set of numbers
in all columns...

Anyway, thanks for both!



--
View this message in context: 
http://r.789695.n4.nabble.com/matrix-of-all-difference-between-rows-values-tp4649191p4649207.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] sample mean, variance and SD

2012-11-10 Thread Jim Lemon

On 11/11/2012 07:09 AM, Greg Snow wrote:

This is to all R-helpers (Sarah is just the one that I am replying to),

Have we become a little too draconian on the "not a homework help list"
issue?
...


As usual, a thoughtful comment on a problem that does not have a 
straightforward solution. The actual responses to obvious homework 
questions range from curt refusals to worked examples. I don't know the 
official status of the "no homework" policy if there is one.


My responses are guided by their expected utility. If the question 
appears to be asked by someone who has just gotten stuck on an esoteric 
quirk of R (and the extraction operators are a good example), I'll try 
to get them over the hump. In this particular case, parvez_200207 seems 
to have answered the question and not realized it. Maybe this was due to 
something that parvez_200207 didn't even know was going on (e.g. a 
sink() was operating) or maybe it was just complete cluelessness. If I 
strongly suspected the former, I probably would have answered.


Jim

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


[R] maximum likelihood estimation in R

2012-11-10 Thread mmosalman
I want to find ML estimates of a model using mle2 in bbmle package. When I
insert new parameters (for new covariates) in model the log-likelihood value
does not change and the estimated value is exactly the initial value that I
determined. What's the problem? This is the code and the result:



As you see the estimated values for b2 , b3 and b4 are the initial values of
them. The log-likelihood value did not change!



--
View this message in context: 
http://r.789695.n4.nabble.com/maximum-likelihood-estimation-in-R-tp4649226.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] For loop question

2012-11-10 Thread dae
Thanks.  That got me the answer.  This works:

symbols = c("IEF","SPY")

getSymbols(symbols)

for(symbol in symbols) { 
assign(symbol, to.monthly(get(symbol), indexAt="endof")) 
   } 
 
#end



--
View this message in context: 
http://r.789695.n4.nabble.com/For-loop-question-tp4649215p4649227.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Plotting the regression curve with its confidence interval

2012-11-10 Thread Осипов Денис
Hello.

How can I plot the regression curve with its confidence interval?
I use nls(y~a*x^b), then plot(x,y), add curve with 
lines(x,predict(nls(y~a*x^b))). But I can't add to plot CI for my curve.

Thanks in advance,
Denis

[[alternative HTML version deleted]]

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


Re: [R] sample mean, variance and SD

2012-11-10 Thread David Winsemius

On Nov 10, 2012, at 6:58 PM, Jim Lemon wrote:

> On 11/11/2012 07:09 AM, Greg Snow wrote:
>> This is to all R-helpers (Sarah is just the one that I am replying to),
>> 
>> Have we become a little too draconian on the "not a homework help list"
>> issue?
>> ...
> 
> As usual, a thoughtful comment on a problem that does not have a 
> straightforward solution. The actual responses to obvious homework questions 
> range from curt refusals to worked examples. I don't know the official status 
> of the "no homework" policy if there is one.

The fourth entry (very close to the top)  in the Posting Guide says:
"Basic statistics and classroom homework: R-help is not intended for 
these."


> My responses are guided by their expected utility. If the question appears to 
> be asked by someone who has just gotten stuck on an esoteric quirk of R (and 
> the extraction operators are a good example), I'll try to get them over the 
> hump.

That's been my approach as well.  I may simply offer:

?

... but if they merely post an obvious homework problem with no effort visible 
I will either ignore it or point to the Posting Guide. Sometimes a preamble 
along the lines of "I tried to do this and cannot get academic support because 
the teacher is using SAS" will be sufficiently convincing. 

> In this particular case, parvez_200207 seems to have answered the question 
> and not realized it.

I wondered whether parvez_200207 wanted to do the same procedure 1000 times and 
record the summary statistics each time. 

> Maybe this was due to something that parvez_200207 didn't even know was going 
> on (e.g. a sink() was operating) or maybe it was just complete cluelessness. 
> If I strongly suspected the former, I probably would have answered.
> 
-- 

David Winsemius, MD
Alameda, CA, USA

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


Re: [R] For loop question

2012-11-10 Thread David Winsemius

On Nov 10, 2012, at 10:17 PM, dae wrote:

> Thanks.  That got me the answer.

Good. That's what the FAQ is for. You should also read the Posting Guide where 
the reasons behind the request to include context for replies is laid out.

>  This works:
> 
> symbols = c("IEF","SPY")
> 
> getSymbols(symbols)
> 
> for(symbol in symbols) { 
>assign(symbol, to.monthly(get(symbol), indexAt="endof")) 
>   } 
> 
> #end
> 
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/For-loop-question-tp4649215p4649227.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
Alameda, CA, USA

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


Re: [R] Plotting the regression curve with its confidence interval

2012-11-10 Thread David Winsemius

On Nov 10, 2012, at 9:36 PM, Осипов Денис wrote:

> Hello.
> 
> How can I plot the regression curve with its confidence interval?
> I use nls(y~a*x^b), then plot(x,y), add curve with 
> lines(x,predict(nls(y~a*x^b))). But I can't add to plot CI for my curve.

Have your read:

?predict.nls  # ?


-- 
David Winsemius, MD
Alameda, CA, USA

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


Re: [R] maximum likelihood estimation in R

2012-11-10 Thread David Winsemius

On Nov 10, 2012, at 9:22 PM, mmosalman wrote:

> I want to find ML estimates of a model using mle2 in bbmle package. When I
> insert new parameters (for new covariates) in model the log-likelihood value
> does not change and the estimated value is exactly the initial value that I
> determined. What's the problem? This is the code and the result:

Nope. The code is not here. It may be visible in the Nabble universe but in the 
Rhelp universe it is completely missing.

> As you see the estimated values for b2 , b3 and b4 are the initial values of
> them. The log-likelihood value did not change!
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/maximum-likelihood-estimation-in-R-tp4649226.html
> Sent from the R help mailing list archive at Nabble.com.

Wrong. Nabble lies. It is not the Rhelp Archive and this message was sent from 
the Mailing list server, not from Nabble.

Please to pay attention to this set of resources.
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Well you apparently did try, so that's something.

-- 

David Winsemius, MD
Alameda, CA, USA

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


Re: [R] Plotting the regression curve with its confidence interval

2012-11-10 Thread Jim Lemon

On 11/11/2012 04:36 PM, Осипов Денис wrote:

Hello.

How can I plot the regression curve with its confidence interval?
I use nls(y~a*x^b), then plot(x,y), add curve with 
lines(x,predict(nls(y~a*x^b))). But I can't add to plot CI for my curve.


Hi Denis,
If you know where you want the lines for the CI the dispersion function 
in the plotrix package will do what you want, use the type=l and 
border=1 arguments with fill=NA.


Jim

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


Re: [R] Plotting the regression curve with its confidence interval

2012-11-10 Thread Осипов Денис
Yes, but it says that arguments, that could help me, now isn't implemented.


> Hello.
>
> How can I plot the regression curve with its confidence interval?
> I use nls(y~a*x^b), then plot(x,y), add curve with 
> lines(x,predict(nls(y~a*x^b))). But I can't add to plot CI for my curve.

> Have your read:
> 
> ?predict.nls  # ?
> 
> David Winsemius, MD
> Alameda, CA, USA
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Plotting the regression curve with its confidence interval

2012-11-10 Thread David Winsemius

On Nov 10, 2012, at 11:48 PM, Осипов Денис wrote:

> Yes, but it says that arguments, that could help me, now isn't implemented.

I think the authors might have had their reasons for leaving it out. There have 
been quite a few threads ofver the years discussing why it is not a 
straightforward task to define a confidence interval. Do you have a particular 
approach that is acceptable in your domain of investigation?

> 
> 
>> Hello.
>> 
>> How can I plot the regression curve with its confidence interval?
>> I use nls(y~a*x^b), then plot(x,y), add curve with 
>> lines(x,predict(nls(y~a*x^b))). But I can't add to plot CI for my curve.
> 
>> Have your read:
>> 
>> ?predict.nls  # ?
>> 
>> David Winsemius, MD
>> Alameda, CA, USA

David Winsemius, MD
Alameda, CA, USA

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