[R] [R ] help in if else in connect the simulation in normal and gamma distribution.

2016-04-07 Thread tan sj
I am new in R. I have to conduct simulation study on the robustness of 2 sample 
tests on several combination of factors (sample sizes ,variance and 
distribution).


I have been completed write a code in normal distribution, and now i wish to 
add if -else in the code so that the code can simulated result for gamma 
distribution also.

But i am stucking again as how can i connect both of them by using if -else?

Can anyone just give me a brief idea on it ?


(i am sorry if this is no related )This is additional question,for gamma, since 
the mean and variance are dependent on each other, so as i assume the null 
hypothesis is TRUE, then do I need to minus the sample mean and add the overall 
mean as well ?in order to make sure that the null hypothesis is TRUE...


Thanks in advance and i am sorry if this is a silly question 


[[alternative HTML version deleted]]

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


Re: [R] why data frame's logical index isnt working

2016-04-07 Thread David Winsemius

> On Apr 7, 2016, at 7:44 PM, Michael Artz  wrote:
> 

> I don't get it, I thought the double index was to indicate and individual 
> element within a column(vector)?

Character values by themselves either quoted or not are not assumed to refer to 
column names unless you use `with` or `within`.


> I will stop using data.frame, thanks a lot!

You will have a lot of problems using R if you stop using data.frames.

-- 
David.
> 
> On Thu, Apr 7, 2016 at 9:29 PM, David Winsemius  
> wrote:
> 
> > On Apr 7, 2016, at 6:46 PM, Michael Artz  wrote:
> >
> > data.frame.$columnToAdd["CurrentColumnName" == "ConditionMet"] <- 1
> >
> > Can someone please explain to me why the above command gives all NAs to
> > columnToAdd?  I thought this was possible in R to do logical expression in
> > the index of a data frame
> 
> It is possible, but please execute this at a console line and then read ?"[" 
> to see what is happening:
> 
> "CurrentColumnName" == "ConditionMet"  # almost surely FALSE
> 
> Let's assume your dataframe were named 'dat'.
> 
> Perhaps you meant to write:
> 
> dat$colToAdd[ dat[["CurrentColumnName"]] == dat[["ConditionMet"]] ] <- 1
> 
> And do please stop naming your dataframes "data.frame".
> 
> 
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> David Winsemius
> Alameda, CA, USA
> 
> 

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Using a function with apply Error: undefined columns selected

2016-04-07 Thread David Winsemius

> On Apr 7, 2016, at 3:39 PM, John Sorkin  wrote:
> 
> I am trying to write a function that can be used to apply to process all the 
> columns of a data.frame. If you will run the code below, you will get the 
> error message undefined columns selected. I hope someone will be able to 
> teach me what I am doing wrong.
> Thank you,
> John 
> 
> # create data frame.
> guppy
> 
> fract2 <- function(col,data) {
>  cat("Prove we have passed the data frame\n")
>  print(data)
> 
>  # Get the name of the column being processed.
>  zz<-deparse(substitute(col))
>  cat("Column being processed\n")
>  print(zz)
>  p<-sum(data[,zz]!="")/length(data[,zz])
>  return(p)
> }
> 
> apply(guppy,2,fract2,data=guppy)

At the point where the error is about to occur during the first column being 
processed, this is what had been printed:

Column being processed
[1] "newX[, i]"

So it should be no surprise that the actual error was:

Error in `[.data.frame`(data, , zz) : undefined columns selected

It occurred at one of the two points where you tried `data[,zz]`

You need to pass colnames(guppy) to fract2 and work with the character values.

All of the *apply function pass only values so they do not pass the column 
names for testing. A possible exception might be the colnames of a vector being 
avaialble when using apply with an index of 1.

-- 



> John David Sorkin M.D., Ph.D.
> 
Snipped

-- 
David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] why data frame's logical index isnt working

2016-04-07 Thread Michael Artz
I don't get it, I thought the double index was to indicate and individual
element within a column(vector)?
I will stop using data.frame, thanks a lot!

On Thu, Apr 7, 2016 at 9:29 PM, David Winsemius 
wrote:

>
> > On Apr 7, 2016, at 6:46 PM, Michael Artz  wrote:
> >
> > data.frame.$columnToAdd["CurrentColumnName" == "ConditionMet"] <- 1
> >
> > Can someone please explain to me why the above command gives all NAs to
> > columnToAdd?  I thought this was possible in R to do logical expression
> in
> > the index of a data frame
>
> It is possible, but please execute this at a console line and then read
> ?"[" to see what is happening:
>
> "CurrentColumnName" == "ConditionMet"  # almost surely FALSE
>
> Let's assume your dataframe were named 'dat'.
>
> Perhaps you meant to write:
>
> dat$colToAdd[ dat[["CurrentColumnName"]] == dat[["ConditionMet"]] ] <- 1
>
> And do please stop naming your dataframes "data.frame".
>
>
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> David Winsemius
> Alameda, CA, USA
>
>

[[alternative HTML version deleted]]

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


Re: [R] R.squared in summary.lm with weights

2016-04-07 Thread Murray Efford
Perhaps I did not make clear that this is not my code - it is the code in 
summary.lm. I used square brackets to try to make my edited version of the text 
intelligible - print summary.lm and you will see where my version fits in.

From: R-help  on behalf of hd625b 

Sent: Friday, 8 April 2016 9:51 a.m.
To: r-help@r-project.org
Subject: Re: [R] R.squared in summary.lm with weights

Do you mean w <-  z$residuals ?
Type names(z) to see the list of item in your model.

I ran your code on a lm and it work fine.
You don't need the brackets around mss <-

Michael Long



On 04/07/2016 02:21 PM, Murray Efford wrote:
> Following some old advice on this list, I have been reading the code for 
> summary.lm to understand the computation of R-squared from a weighted 
> regression. Usually weights in lm are applied to squared residuals, but I see 
> that the weighted mean of the observations is calculated as if the weights 
> are on the original scale:
>
> [...]
>  f <- z$fitted.values
>  w <- z$weights
> [...]
>  m <- sum(w * f/sum(w))
>  [mss <-]  sum(w * (f - m)^2)
> [...]
>
> This seems inconsistent to me. What am I missing?
>
> Murray Efford
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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

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


Re: [R] R.squared in summary.lm with weights

2016-04-07 Thread hd625b

Do you mean w <-  z$residuals ?
Type names(z) to see the list of item in your model.

I ran your code on a lm and it work fine.
You don't need the brackets around mss <-

Michael Long



On 04/07/2016 02:21 PM, Murray Efford wrote:

Following some old advice on this list, I have been reading the code for 
summary.lm to understand the computation of R-squared from a weighted 
regression. Usually weights in lm are applied to squared residuals, but I see 
that the weighted mean of the observations is calculated as if the weights are 
on the original scale:

[...]
 f <- z$fitted.values
 w <- z$weights
[...]
 m <- sum(w * f/sum(w))
 [mss <-]  sum(w * (f - m)^2)
[...]

This seems inconsistent to me. What am I missing?

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


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


Re: [R] why data frame's logical index isnt working

2016-04-07 Thread David Winsemius

> On Apr 7, 2016, at 6:46 PM, Michael Artz  wrote:
> 
> data.frame.$columnToAdd["CurrentColumnName" == "ConditionMet"] <- 1
> 
> Can someone please explain to me why the above command gives all NAs to
> columnToAdd?  I thought this was possible in R to do logical expression in
> the index of a data frame

It is possible, but please execute this at a console line and then read ?"[" to 
see what is happening:

"CurrentColumnName" == "ConditionMet"  # almost surely FALSE

Let's assume your dataframe were named 'dat'.

Perhaps you meant to write:

dat$colToAdd[ dat[["CurrentColumnName"]] == dat[["ConditionMet"]] ] <- 1

And do please stop naming your dataframes "data.frame".


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

David Winsemius
Alameda, CA, USA

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

2016-04-07 Thread David Winsemius

> On Apr 7, 2016, at 1:25 PM, John Sorkin  wrote:
> 
> 
> ‪‪I would like to apply a function, fract, to the columns of a
> dataframe. I tried the following 
> apply(data5NonEventEpochs,2,fract)
> but, no surprise it did not work as apply works on matrices not data
> frames.

As Bert pointed out your analsysis is incorrect. If `fract` is  function that 
takes a single vector then you should have gotten back a list or a matrix with 
as many entries or columns as the data5NonEventEpochs had columns.

So to do anything further, please post the output of dput(fract)

-- 
David.

> How can I apply a fuction to the columns of a data frame? (I
> can't covert data5NonEventsEpochs to a matrix as it contains character
> data).
> Thank you,
> John
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing) 
> 
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:16}}

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

Re: [R] why data frame's logical index isnt working

2016-04-07 Thread Richard M. Heiberger
you probably mean something like this

data.frame.$columnToAdd <- (data.frame.$CurrentColumnName ==
data.frame.$ConditionMet)

what you did is compare two character strings.  They are not the same.
Therefore a new column
is created with the default value NA.

> tmp <- data.frame(A=1:4, B=c(1,3,4,5))
> tmp
  A B
1 1 1
2 2 3
3 3 4
4 4 5
> tmp$C <- tmp$A == tmp$B
> tmp
  A B C
1 1 1  TRUE
2 2 3 FALSE
3 3 4 FALSE
4 4 5 FALSE
> tmp$D["A" == "B"] <- 1
> tmp
  A B C  D
1 1 1  TRUE NA
2 2 3 FALSE NA
3 3 4 FALSE NA
4 4 5 FALSE NA
>

On Thu, Apr 7, 2016 at 9:46 PM, Michael Artz  wrote:
> data.frame.$columnToAdd["CurrentColumnName" == "ConditionMet"] <- 1
>
> Can someone please explain to me why the above command gives all NAs to
> columnToAdd?  I thought this was possible in R to do logical expression in
> the index of a data frame
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] simple question on data frames assignment

2016-04-07 Thread Michael Artz
Why am I better off with true and false?

On Thu, Apr 7, 2016 at 8:41 AM, Hadley Wickham  wrote:

> == is also vectorised, and you're better off with TRUE and FALSE
> rather than 1 and 0, so I'd recommend:
>
> colordata$response <- colordata$color == 'blue'
>
> Hadley
>
> On Thu, Apr 7, 2016 at 6:52 AM, David Barron  wrote:
> > ifelse is vectorised, so just use that without the loop.
> >
> > colordata$response <- ifelse(colordata$color == 'blue', 1, 0)
> >
> > David
> >
> > On 7 April 2016 at 12:41, Michael Artz  wrote:
> >
> >> Hi I'm not sure how to ask this, but its a very easy question to answer
> for
> >> an R person.
> >>
> >> What is an easy way to check for a column value and then assigne a new
> >> column a value based on that old column value?
> >>
> >> For example, Im doing
> >>  colordata <- data.frame(id = c(1,2,3,4,5), color = c("blue", "red",
> >> "green", "blue", "orange"))
> >>  for (i in 1:nrow(colordata)){
> >>colordata$response[i] <- ifelse(colordata[i,"color"] == "blue", 1, 0)
> >>  }
> >>
> >> which works,  but I don't want to use the for loop I want to "vecotrize"
> >> this.  How would this be implemented?
> >>
> >> [[alternative HTML version deleted]]
> >>
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
> http://hadley.nz
>

[[alternative HTML version deleted]]

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


Re: [R] simple question on data frames assignment

2016-04-07 Thread Michael Artz
Fyi, This statement returned the following error

'Error in "Yes" + 0 : non-numeric argument to binary operator'

On Thu, Apr 7, 2016 at 8:43 AM,  wrote:

> Hello,
>
> Or even simpler, without ifelse,
>
> colordata$response <- colordata$color == 'blue' + 0
>
> Hope this helps,
>
> Rui Barradas
>
>
> Citando David Barron :
>
> ifelse is vectorised, so just use that without the loop.
>
> colordata$response <- ifelse(colordata$color == 'blue', 1, 0)
>
> David
>
> On 7 April 2016 at 12:41, Michael Artz  wrote:
>
> Hi I'm not sure how to ask this, but its a very easy question to answer for
> an R person.
>
> What is an easy way to check for a column value and then assigne a new
> column a value based on that old column value?
>
> For example, Im doing
> colordata <- data.frame(id = c(1,2,3,4,5), color = c("blue", "red",
> "green", "blue", "orange"))
> for (i in 1:nrow(colordata)){
>colordata$response[i] <- ifelse(colordata[i,"color"] == "blue", 1, 0)
> }
>
> which works,  but I don't want to use the for loop I want to "vecotrize"
> this.  How would this be implemented?
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.htmland provide commented,
> minimal, self-contained, reproducible code.
>
>
>
>

[[alternative HTML version deleted]]

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


[R] why data frame's logical index isnt working

2016-04-07 Thread Michael Artz
data.frame.$columnToAdd["CurrentColumnName" == "ConditionMet"] <- 1

Can someone please explain to me why the above command gives all NAs to
columnToAdd?  I thought this was possible in R to do logical expression in
the index of a data frame

[[alternative HTML version deleted]]

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


Re: [R] Using a function with apply Error: undefined columns selected

2016-04-07 Thread Jim Lemon
Hi John,
First, apply isn't guaranteed to work on data frames. There are two
easy ways to do something like this, but we had better have a data
frame:

guppy<-data.frame(taste=rnorm(10,5),
 crunch=rnorm(10,5),satiety=rnorm(10,5))

If you just want to apply a function to all or a subset of columns of
a data frame, a for loop can be used:

fract2.1<-function(col,data) {
 p<-sum(data[,col],na.rm=TRUE)/sum(!is.na(data[,col]))
 return(p)
}
for(col in 1:ncol(guppy)) print(fract2.1(col,guppy))

If you really do want to use an "*apply" function, then the function
has to be written for each column, not the entire data frame:

fract2.2<-function(x) return(sum(x,na.rm=TRUE)/sum(!is.na(x)))
sapply(guppy,fract2.2)

and if you want a subset of the columns, you will have to do it before
you let sapply get into it.

Jim



On Fri, Apr 8, 2016 at 8:39 AM, John Sorkin  wrote:
> I am trying to write a function that can be used to apply to process all the 
> columns of a data.frame. If you will run the code below, you will get the 
> error message undefined columns selected. I hope someone will be able to 
> teach me what I am doing wrong.
> Thank you,
> John
>
> # create data frame.
> guppy
>
> fract2 <- function(col,data) {
>   cat("Prove we have passed the data frame\n")
>   print(data)
>
>   # Get the name of the column being processed.
>   zz<-deparse(substitute(col))
>   cat("Column being processed\n")
>   print(zz)
>   p<-sum(data[,zz]!="")/length(data[,zz])
>   return(p)
> }
>
> apply(guppy,2,fract2,data=guppy)
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and 
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:12}}

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Using a function with apply Error: undefined columns selected

2016-04-07 Thread John Sorkin
I am trying to write a function that can be used to apply to process all the 
columns of a data.frame. If you will run the code below, you will get the error 
message undefined columns selected. I hope someone will be able to teach me 
what I am doing wrong.
Thank you,
John 
 
# create data frame.
guppy
 
fract2 <- function(col,data) {
  cat("Prove we have passed the data frame\n")
  print(data)
  
  # Get the name of the column being processed.
  zz<-deparse(substitute(col))
  cat("Column being processed\n")
  print(zz)
  p<-sum(data[,zz]!="")/length(data[,zz])
  return(p)
}
 
apply(guppy,2,fract2,data=guppy)
John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric 
Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing) 

Confidentiality Statement:
This email message, including any attachments, is for the sole use of the 
intended recipient(s) and may contain confidential and privileged information. 
Any unauthorized use, disclosure or distribution is prohibited. If you are not 
the intended recipient, please contact the sender by reply email and destroy 
all copies of the original message. 
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] using apply to a data frame

2016-04-07 Thread Peter Langfelder
Use lapply or sapply. A data frame is also a list with each component
representing one column; lapply/sapply will apply the function to each
column.

Peter

On Thu, Apr 7, 2016 at 1:25 PM, John Sorkin  wrote:
>
> ‪‪I would like to apply a function, fract, to the columns of a
> dataframe. I tried the following
> apply(data5NonEventEpochs,2,fract)
> but, no surprise it did not work as apply works on matrices not data
> frames. How can I apply a fuction to the columns of a data frame? (I
> can't covert data5NonEventsEpochs to a matrix as it contains character
> data).
> Thank you,
> John
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:12}}

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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.squared in summary.lm with weights

2016-04-07 Thread Murray Efford
Following some old advice on this list, I have been reading the code for 
summary.lm to understand the computation of R-squared from a weighted 
regression. Usually weights in lm are applied to squared residuals, but I see 
that the weighted mean of the observations is calculated as if the weights are 
on the original scale:

[...]
f <- z$fitted.values
w <- z$weights
[...]
m <- sum(w * f/sum(w))
[mss <-]  sum(w * (f - m)^2)
[...]

This seems inconsistent to me. What am I missing?

Murray Efford
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] using apply to a data frame

2016-04-07 Thread Bert Gunter
Inline.

-- Bert
Bert Gunter




On Thu, Apr 7, 2016 at 1:25 PM, John Sorkin  wrote:
>
> ‪‪I would like to apply a function, fract, to the columns of a
> dataframe. I tried the following
> apply(data5NonEventEpochs,2,fract)
> but, no surprise it did not work as apply works on matrices not data
> frames.

That is false! From ?apply:

"If X is not an array but an object of a class with a non-null dim
value (such as a data frame), apply attempts to coerce it to an array
via as.matrix if it is two-dimensional (e.g., a data frame) or via
as.array."

Your apply() call would not have worked with a matrix either, as your
syntax was wrong.  Here is a corrected example:

> X <- data.frame(a=1:5,b=6:10)

> apply(X,2,function(x)mean(sqrt(x)))
   ab
1.676466 2.817189






 How can I apply a fuction to the columns of a data frame? (I
> can't covert data5NonEventsEpochs to a matrix as it contains character
> data).
> Thank you,
> John
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:12}}

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

2016-04-07 Thread Luisfo Chiroque via R-help
Dear John,

Try using
sapply(data5NonEventEpochs, fract)

HTH

Best,
Luisfo Chiroque
PhD Student
IMDEA Networks Institute
http://fourier.networks.imdea.org/people/~luis_nunez/ 

> El 7 abr 2016, a las 23:25, John Sorkin  
> escribió:
> 
> 
> ‪‪I would like to apply a function, fract, to the columns of a
> dataframe. I tried the following 
> apply(data5NonEventEpochs,2,fract)
> but, no surprise it did not work as apply works on matrices not data
> frames. How can I apply a fuction to the columns of a data frame? (I
> can't covert data5NonEventsEpochs to a matrix as it contains character
> data).
> Thank you,
> John
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing) 
> 
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:16}}

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

[R] using apply to a data frame

2016-04-07 Thread John Sorkin

‪‪I would like to apply a function, fract, to the columns of a
dataframe. I tried the following 
apply(data5NonEventEpochs,2,fract)
but, no surprise it did not work as apply works on matrices not data
frames. How can I apply a fuction to the columns of a data frame? (I
can't covert data5NonEventsEpochs to a matrix as it contains character
data).
Thank you,
John
John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and
Geriatric Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing) 

Confidentiality Statement:
This email message, including any attachments, is for the sole use of
the intended recipient(s) and may contain confidential and privileged
information. Any unauthorized use, disclosure or distribution is
prohibited. If you are not the intended recipient, please contact the
sender by reply email and destroy all copies of the original message. 
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] Question about R Ver.2.7.2 compatible with JAVA 8

2016-04-07 Thread Duncan Murdoch

On 07/04/2016 11:31 AM, Rajamoorthy-CW, Thirumurugan 8361 wrote:

Hi Team,

We (Otsuka IT team) are planning to upgrade JAVA 8 to Biometrics department 
servers. On account of this, we want to make sure R Ver.2.7.2 is working fine 
in JAVA 8?
Please let us know if R Ver.2.7.2 is compatible with JAVA 8?


R 2.7.2 is very old --- it was released nearly 8 years ago.   I think 
you're going to have to do the testing yourself, unless you're very 
lucky that someone remembers.


Duncan Murdoch






Regards

Thirumurugan Rajamoorthy 
|thirumurugan.rajamoorthy...@otsuka-us.com|
 �: (240)780-4194
Managed Service Provider, Biometrics Support Member, HCL Technologies.
A Member of the Otsuka Information Technology (OIT) Network.
In Support of Global R IT Services.


[[alternative HTML version deleted]]



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


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

Re: [R] Storing output of loop into list()

2016-04-07 Thread Adams, Jean
You don't need a for loop for the first part.  You can do it like this:

Notice that I used unchanging data for the temps vector so that you could
tell us what output you expect to see, in case what I provide is not
adequate.

temps <- c(13.988, 13.932, 14.039, 14.082, 13.998, 13.93, 14.028, 14.015,
  14.06, 14.092, 14.089, 13.971, 14.062, 14.001, 13.959, 14.046,
  14.034, 14.089, 13.991, 13.982, 14.038, 14.001, 13.973, 13.966,
  13.995, 13.934, 14.101, 14.087, 14.064, 14.06, 14.027, 13.996,
  14.037, 14.024, 14.032, 14.052, 13.986, 14.021, 13.988, 13.98,
  13.968, 13.959, 14.055, 13.978, 14.105, 14.005, 13.996, 14.027,
  13.99, 13.966, 14.047, 13.903, 13.953, 14.02, 13.969, 14.051,
  14.027, 14.03, 14.078, 13.988, 14.007, 13.899, 14.023, 13.991,
  13.993, 13.973, 14.035, 14.091, 14.033, 13.943, 14.08, 14, 14.015,
  14.042, 13.993, 14.064, 14.039, 13.939, 13.95, 14.017, 13.984,
  14.075, 14.006, 14.029, 14.004, 13.974, 14.003, 14.073, 13.991,
  13.973, 14.029, 14.02, 14.032, 14.036, 14.021, 13.983, 13.981,
  13.977, 13.94, 14.014)

tempdif9 <- -diff(temps, lag=9)
L <- length(tempdif9)
sel <- tempdif9[-L] >= 0.1 & tempdif9[-1] > -0.05
ttind <- cbind(tempdif9, index=1:L)[sel, ]
ttind

 tempdif9 index
[1,]0.10110
[2,]0.10017
[3,]0.10128
[4,]0.15243

I'm not sure what you are trying to achieve with the second part.  I
suspect that what you really wanted is to see the temperatures that
contributed to the output in ttind.  If that's the case, then perhaps this
will help.

contrib <- t(sapply(ttind[, "index"], function(i) temps[i + 0:8]))
contrib

   [,1]   [,2]   [,3]   [,4]   [,5]   [,6]   [,7]   [,8]   [,9]
[1,] 14.092 14.089 13.971 14.062 14.001 13.959 14.046 14.034 14.089
[2,] 14.034 14.089 13.991 13.982 14.038 14.001 13.973 13.966 13.995
[3,] 14.087 14.064 14.060 14.027 13.996 14.037 14.024 14.032 14.052
[4,] 14.055 13.978 14.105 14.005 13.996 14.027 13.990 13.966 14.047

Jean


On Thu, Apr 7, 2016 at 11:09 AM,  wrote:

> Hello. I am trying to store the output from a loop into a matrix. Failed
> so far, thanks for the help.
>
> What I want to store into a new matrix: (just run the code once):
>
> temps<-rnorm(400,14,0.05)
> ttind<-NULL
> for(ti in 1:(length(temps)-9)) {
>   if(temps[ti]-temps[ti+9] >= 0.1 && max(temps[ti]-temps[ti+1:9]) > -0.05)
> ttind<-c(ttind,ti)
> }
> for(ti in 1:length(ttind)) {
>
>  print(round(temps[ttind[ti]:(ttind[ti]+9)],3))
>
>   }
>
>
>
>
>
>
>
> My (failed) soultion attempt:
>
> temps<-rnorm(400,14,0.05)
> ttind<-NULL
> for(ti in 1:(length(temps)-9)) {
>   if(temps[ti]-temps[ti+9] >= 0.1 && max(temps[ti]-temps[ti+1:9]) > -0.05)
> ttind<-c(ttind,ti)
> }
>
> outputList = list()
> counter = 1
>
> for(ti in 1:length(ttind)) {
>
>   outputList[i] <-  print(round(temps[ttind[ti]:(ttind[ti]+9)],3))
> counter= counter+1
>   }
>
> print(outputList)
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] Question about R Ver.2.7.2 compatible with JAVA 8

2016-04-07 Thread Rajamoorthy-CW, Thirumurugan 8361
Hi Team,

We (Otsuka IT team) are planning to upgrade JAVA 8 to Biometrics department 
servers. On account of this, we want to make sure R Ver.2.7.2 is working fine 
in JAVA 8?
Please let us know if R Ver.2.7.2 is compatible with JAVA 8?




Regards

Thirumurugan Rajamoorthy 
|thirumurugan.rajamoorthy...@otsuka-us.com|
 �: (240)780-4194
Managed Service Provider, Biometrics Support Member, HCL Technologies.
A Member of the Otsuka Information Technology (OIT) Network.
In Support of Global R IT Services.


[[alternative HTML version deleted]]

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

Re: [R] Storing output of loop into list()

2016-04-07 Thread Bert Gunter
Have a look at ?lapply, which will do this for you.

Have you spent time with an R tutorial or two. There are many good
ones on the web that discuss this sort of thig.

Cheers,
Bert


Bert Gunter

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


On Thu, Apr 7, 2016 at 9:09 AM,   wrote:
> Hello. I am trying to store the output from a loop into a matrix. Failed so 
> far, thanks for the help.
>
> What I want to store into a new matrix: (just run the code once):
>
> temps<-rnorm(400,14,0.05)
> ttind<-NULL
> for(ti in 1:(length(temps)-9)) {
>   if(temps[ti]-temps[ti+9] >= 0.1 && max(temps[ti]-temps[ti+1:9]) > -0.05)
> ttind<-c(ttind,ti)
> }
> for(ti in 1:length(ttind)) {
>
>  print(round(temps[ttind[ti]:(ttind[ti]+9)],3))
>
>   }
>
>
>
>
>
>
>
> My (failed) soultion attempt:
>
> temps<-rnorm(400,14,0.05)
> ttind<-NULL
> for(ti in 1:(length(temps)-9)) {
>   if(temps[ti]-temps[ti+9] >= 0.1 && max(temps[ti]-temps[ti+1:9]) > -0.05)
> ttind<-c(ttind,ti)
> }
>
> outputList = list()
> counter = 1
>
> for(ti in 1:length(ttind)) {
>
>   outputList[i] <-  print(round(temps[ttind[ti]:(ttind[ti]+9)],3))
> counter= counter+1
>   }
>
> print(outputList)
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Storing output of loop into list()

2016-04-07 Thread maettuw
Hello. I am trying to store the output from a loop into a matrix. Failed so 
far, thanks for the help.

What I want to store into a new matrix: (just run the code once):

temps<-rnorm(400,14,0.05)
ttind<-NULL
for(ti in 1:(length(temps)-9)) {
  if(temps[ti]-temps[ti+9] >= 0.1 && max(temps[ti]-temps[ti+1:9]) > -0.05)
ttind<-c(ttind,ti)
}
for(ti in 1:length(ttind)) {

 print(round(temps[ttind[ti]:(ttind[ti]+9)],3))

  }







My (failed) soultion attempt:

temps<-rnorm(400,14,0.05)
ttind<-NULL
for(ti in 1:(length(temps)-9)) {
  if(temps[ti]-temps[ti+9] >= 0.1 && max(temps[ti]-temps[ti+1:9]) > -0.05)
ttind<-c(ttind,ti)
}

outputList = list()
counter = 1

for(ti in 1:length(ttind)) {

  outputList[i] <-  print(round(temps[ttind[ti]:(ttind[ti]+9)],3))
counter= counter+1
  }

print(outputList)


[[alternative HTML version deleted]]

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


Re: [R] simple question on data frames assignment

2016-04-07 Thread Michael Artz
It all makes so much sense now

On Thu, Apr 7, 2016 at 10:04 AM, Jeff Newmiller 
wrote:

> lapply(colordata2[ -1 ], f )
>
> When you put the parentheses on, you are calling the function yourself
> before lapply gets a chance. The error pops up because you are giving a
> vector of numbers (the answer f gave you) to the second argument of lapply
> instead of a function.
> --
> Sent from my phone. Please excuse my brevity.
>
> On April 7, 2016 7:31:18 AM PDT, Michael Artz 
> wrote:
>>
>> If you are not using an anonymous function and say you had written the
>> function out
>>
>> The below gives me the error > 'f(colordata2$color1)' is not a function,
>> character or symbol'  But then how is the anonymous function working?
>>
>>
>> f <- function(col){
>>   ifelse(col == 'blue', 1, 0)
>> }
>> responses <- lapply(colordata2[ -1 ], f(colordata2$color1) )
>>
>> 'f(colordata2$color1)' is not a function, character or symbol'
>>
>> then how could you then use this fuction in lapply if not for the
>> anonymous function?
>>
>> On Thu, Apr 7, 2016 at 8:17 AM, Jeff Newmiller 
>> wrote:
>>
>>> Lapply is not a vectorized function. It is compact to read, but it would
>>> not be worth using for this calculation.
>>>
>>> However, if your data frame had multiple color columns in your data
>>> frame that you wanted to make responses for then you might want to use
>>> lapply as a more compact version of a for loop to repeat this operation.
>>>
>>> colordata2 <- data.frame(id = c(1,2,3,4,5), color1 = c("blue", "red",
>>> "green", "blue", "orange"), color2 = c("orange", "green",
>>> "blue", "red", "red"))
>>> responses <- lapply( colordata2[ -1 ], function(col) { ifelse(col ==
>>> 'blue', 1, 0) } )
>>> names(responses) <- names( colordata2 )[-1]
>>>
>>> where each of the columns other than the first is handed in turn to the
>>> anonymous function that does the response calculation. The result is a data
>>> frame (list of columns) with no column names, so I give the new columns
>>> names based on the old column names. You could choose different names, e.g.
>>>
>>> names(responses) <- paste0( "response", 1:2 )
>>>
>>> but you have to be careful to fix that code whenever you change the
>>> colordata2 data frame to have more columns.
>>> --
>>> Sent from my phone. Please excuse my brevity.
>>>
>>> On April 7, 2016 4:57:04 AM PDT, Michael Artz 
>>> wrote:

 Thaks so much!  And how would you incorporate lapply() here?

 On Thu, Apr 7, 2016 at 6:52 AM, David Barron  wrote:

  ifelse is vectorised, so just use that without the loop.
>
>  colordata$response <- ifelse(colordata$color == 'blue', 1, 0)
>
>  David
>
>  On 7 April 2016 at 12:41, Michael Artz  wrote:
>
>  Hi I'm not sure how to ask this, but its a very easy question to answer
>>  for
>>  an R person.
>>
>>  What is an easy way to check for a column value and
>> then assigne a new
>>  column a value based on that old column value?
>>
>>  For example, Im doing
>>   colordata <- data.frame(id = c(1,2,3,4,5),
>> color = c("blue", "red",
>>  "green", "blue", "orange"))
>>   for (i in 1:nrow(colordata)){
>> colordata$response[i] <- ifelse(colordata[i,"color"] == "blue", 1, 0)
>>   }
>>
>>  which works,  but I don't want to use the for loop I want to "vecotrize"
>>  this.  How would this be implemented?
>>
>>  [[alternative HTML version deleted]]
>>
>> --
>>
>>  R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>  https://stat.ethz.ch/mailman/listinfo/r-help
>>  PLEASE do read the posting guide
>>  http://www.R-project.org/posting-guide.html
>>  and provide commented, minimal, self-contained, reproducible
>> code.
>
>
>

  [[alternative HTML version deleted]]

 --

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


>>

[[alternative HTML version deleted]]

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


Re: [R] simple question on data frames assignment

2016-04-07 Thread Jeff Newmiller
lapply(colordata2[ -1 ], f )

When you put the parentheses on, you are calling the function yourself before 
lapply gets a chance. The error pops up because you are giving a vector of 
numbers (the answer f gave you) to the second argument of lapply instead of a 
function. 
-- 
Sent from my phone. Please excuse my brevity.

On April 7, 2016 7:31:18 AM PDT, Michael Artz  wrote:
>If you are not using an anonymous function and say you had written the
>function out
>
>The below gives me the error > 'f(colordata2$color1)' is not a
>function,
>character or symbol'  But then how is the anonymous function working?
>
>
>f <- function(col){
>  ifelse(col == 'blue', 1, 0)
>}
>responses <- lapply(colordata2[ -1 ], f(colordata2$color1) )
>
>'f(colordata2$color1)' is not a function, character or symbol'
>
>then how could you then use this fuction in lapply if not for the
>anonymous
>function?
>
>On Thu, Apr 7, 2016 at 8:17 AM, Jeff Newmiller
>
>wrote:
>
>> Lapply is not a vectorized function. It is compact to read, but it
>would
>> not be worth using for this calculation.
>>
>> However, if your data frame had multiple color columns in your data
>frame
>> that you wanted to make responses for then you might want to use
>lapply as
>> a more compact version of a for loop to repeat this operation.
>>
>> colordata2 <- data.frame(id = c(1,2,3,4,5), color1 = c("blue", "red",
>> "green", "blue", "orange"), color2 = c("orange", "green",
>> "blue", "red", "red"))
>> responses <- lapply( colordata2[ -1 ], function(col) { ifelse(col ==
>> 'blue', 1, 0) } )
>> names(responses) <- names( colordata2 )[-1]
>>
>> where each of the columns other than the first is handed in turn to
>the
>> anonymous function that does the response calculation. The result is
>a data
>> frame (list of columns) with no column names, so I give the new
>columns
>> names based on the old column names. You could choose different
>names, e.g.
>>
>> names(responses) <- paste0( "response", 1:2 )
>>
>> but you have to be careful to fix that code whenever you change the
>> colordata2 data frame to have more columns.
>> --
>> Sent from my phone. Please excuse my brevity.
>>
>> On April 7, 2016 4:57:04 AM PDT, Michael Artz
>
>> wrote:
>>>
>>> Thaks so much!  And how would you incorporate lapply() here?
>>>
>>> On Thu, Apr 7, 2016 at 6:52 AM, David Barron 
>wrote:
>>>
>>>  ifelse is vectorised, so just use that without the loop.

  colordata$response <- ifelse(colordata$color == 'blue', 1, 0)

  David

  On 7 April 2016 at 12:41, Michael Artz 
>wrote:

  Hi I'm not sure how to ask this, but its a very easy question to
>answer
>  for
>  an R person.
>
>  What is an easy way to check for a column value and then assigne
>a new
>  column a value based on that old column value?
>
>  For example, Im doing
>   colordata <- data.frame(id = c(1,2,3,4,5),
> color = c("blue", "red",
>  "green", "blue", "orange"))
>   for (i in 1:nrow(colordata)){
> colordata$response[i] <- ifelse(colordata[i,"color"] ==
>"blue", 1, 0)
>   }
>
>  which works,  but I don't want to use the for loop I want to
>"vecotrize"
>  this.  How would this be implemented?
>
>  [[alternative HTML version deleted]]
>
> --
>
>  R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>  https://stat.ethz.ch/mailman/listinfo/r-help
>  PLEASE do read the posting guide
>  http://www.R-project.org/posting-guide.html
>  and provide commented, minimal, self-contained, reproducible
>code.



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

[[alternative HTML version deleted]]

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


Re: [R] dynamic reports with sweave: error when compiling the tex-file

2016-04-07 Thread John Kane
Definitely yes I just tried a one line latex document and it bombed with 
\begin{ document } but is fine with \begin{document} .

I think the spaces within the {} must all be removed. Latex does not like spaces

John Kane
Kingston ON Canada


> -Original Message-
> From: jdnew...@dcn.davis.ca.us
> Sent: Thu, 07 Apr 2016 05:42:57 -0700
> To: palad...@trustindata.de, r-help@r-project.org
> Subject: Re: [R] dynamic reports with sweave: error when compiling the
> tex-file
> 
> Did you really put spaces between the backslashes and the keywords? That
> would be a problem...
> --
> Sent from my phone. Please excuse my brevity.
> 
> On April 7, 2016 4:32:29 AM PDT, palad...@trustindata.de wrote:
> >Hello,
> >I took my first steps in dynamic reports with Gnu R and used sweave().
>> 
> >I therefore run Sweave() with an example of Friedrich Leisch, starting
>> 
> >like this:
>> 
> >\ documentclass [ a4paper ]{ article }
> >\ title { Sweave Example 1}
> >\ author { Friedrich Leisch }
> >\ begin { document }
> >\ maketitle
> >and so on.
>> 
> >It worked very well but when I tried to compile the latex file I get
> >this error message: ! LaTeX Error: Missing \begin{document}."
>> 
>> 
> >But clearly there is a "begin{document}"
>> 
> >I looked for a clue searching the internet and read that maybe my
> >editor writes invisible signs, so called boms, so that "\begin
> >{document} " is not really at the beginninng but these boms.
>> 
> >Unfortunatly I have not the faintest how to solve the problem.
>> 
> >(I am using GNU R 3.01 and windows10 and installed MiKTex.)
>> 
> >It would be really nice if someone could help me!
>> 
>> 
> >Best  regards and thanking you in anticipation.
>> 
> >Claudia
>> 
> >__
> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide
> >http://www.R-project.org/posting-guide.html
> >and provide commented, minimal, self-contained, reproducible code.
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


FREE ONLINE PHOTOSHARING - Share your photos online with your friends and 
family!
Visit http://www.inbox.com/photosharing to find out more!

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

2016-04-07 Thread Michael Artz
If you are not using an anonymous function and say you had written the
function out

The below gives me the error > 'f(colordata2$color1)' is not a function,
character or symbol'  But then how is the anonymous function working?


f <- function(col){
  ifelse(col == 'blue', 1, 0)
}
responses <- lapply(colordata2[ -1 ], f(colordata2$color1) )

'f(colordata2$color1)' is not a function, character or symbol'

then how could you then use this fuction in lapply if not for the anonymous
function?

On Thu, Apr 7, 2016 at 8:17 AM, Jeff Newmiller 
wrote:

> Lapply is not a vectorized function. It is compact to read, but it would
> not be worth using for this calculation.
>
> However, if your data frame had multiple color columns in your data frame
> that you wanted to make responses for then you might want to use lapply as
> a more compact version of a for loop to repeat this operation.
>
> colordata2 <- data.frame(id = c(1,2,3,4,5), color1 = c("blue", "red",
> "green", "blue", "orange"), color2 = c("orange", "green",
> "blue", "red", "red"))
> responses <- lapply( colordata2[ -1 ], function(col) { ifelse(col ==
> 'blue', 1, 0) } )
> names(responses) <- names( colordata2 )[-1]
>
> where each of the columns other than the first is handed in turn to the
> anonymous function that does the response calculation. The result is a data
> frame (list of columns) with no column names, so I give the new columns
> names based on the old column names. You could choose different names, e.g.
>
> names(responses) <- paste0( "response", 1:2 )
>
> but you have to be careful to fix that code whenever you change the
> colordata2 data frame to have more columns.
> --
> Sent from my phone. Please excuse my brevity.
>
> On April 7, 2016 4:57:04 AM PDT, Michael Artz 
> wrote:
>>
>> Thaks so much!  And how would you incorporate lapply() here?
>>
>> On Thu, Apr 7, 2016 at 6:52 AM, David Barron  wrote:
>>
>>  ifelse is vectorised, so just use that without the loop.
>>>
>>>  colordata$response <- ifelse(colordata$color == 'blue', 1, 0)
>>>
>>>  David
>>>
>>>  On 7 April 2016 at 12:41, Michael Artz  wrote:
>>>
>>>  Hi I'm not sure how to ask this, but its a very easy question to answer
  for
  an R person.

  What is an easy way to check for a column value and then assigne a new
  column a value based on that old column value?

  For example, Im doing
   colordata <- data.frame(id = c(1,2,3,4,5),
 color = c("blue", "red",
  "green", "blue", "orange"))
   for (i in 1:nrow(colordata)){
 colordata$response[i] <- ifelse(colordata[i,"color"] == "blue", 1, 0)
   }

  which works,  but I don't want to use the for loop I want to "vecotrize"
  this.  How would this be implemented?

  [[alternative HTML version deleted]]

 --

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

[[alternative HTML version deleted]]

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


Re: [R] simple question on data frames assignment

2016-04-07 Thread ruipbarradas
Hello,

Or even simpler, without ifelse,

colordata$response <- colordata$color == 'blue' + 0

Hope this helps,

Rui Barradas
 

Citando David Barron :

> ifelse is vectorised, so just use that without the loop.
>
> colordata$response <- ifelse(colordata$color == 'blue', 1, 0)
>
> David
>
> On 7 April 2016 at 12:41, Michael Artz  wrote:
>> Hi I'm not sure how to ask this, but its a very easy question to answer for
>> an R person.
>>
>> What is an easy way to check for a column value and then assigne a new
>> column a value based on that old column value?
>>
>> For example, Im doing
>> colordata <- data.frame(id = c(1,2,3,4,5), color = c("blue", "red",
>> "green", "blue", "orange"))
>> for (i in 1:nrow(colordata)){
>>    colordata$response[i] <- ifelse(colordata[i,"color"] == "blue", 1, 0)
>> }
>>
>> which works,  but I don't want to use the for loop I want to "vecotrize"
>> this.  How would this be implemented?
>>
>>         [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide  
> http://www.R-project.org/posting-guide.htmland provide commented,  
> minimal, self-contained, reproducible code.

 

[[alternative HTML version deleted]]

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

Re: [R] simple question on data frames assignment

2016-04-07 Thread Hadley Wickham
== is also vectorised, and you're better off with TRUE and FALSE
rather than 1 and 0, so I'd recommend:

colordata$response <- colordata$color == 'blue'

Hadley

On Thu, Apr 7, 2016 at 6:52 AM, David Barron  wrote:
> ifelse is vectorised, so just use that without the loop.
>
> colordata$response <- ifelse(colordata$color == 'blue', 1, 0)
>
> David
>
> On 7 April 2016 at 12:41, Michael Artz  wrote:
>
>> Hi I'm not sure how to ask this, but its a very easy question to answer for
>> an R person.
>>
>> What is an easy way to check for a column value and then assigne a new
>> column a value based on that old column value?
>>
>> For example, Im doing
>>  colordata <- data.frame(id = c(1,2,3,4,5), color = c("blue", "red",
>> "green", "blue", "orange"))
>>  for (i in 1:nrow(colordata)){
>>colordata$response[i] <- ifelse(colordata[i,"color"] == "blue", 1, 0)
>>  }
>>
>> which works,  but I don't want to use the for loop I want to "vecotrize"
>> this.  How would this be implemented?
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
http://hadley.nz

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

2016-04-07 Thread Jeff Newmiller
Lapply is not a vectorized function. It is compact to read, but it would not be 
worth using for this calculation. 

However, if your data frame had multiple color columns in your data frame that 
you wanted to make responses for then you might want to use lapply as a more 
compact version of a for loop to repeat this operation. 

colordata2 <- data.frame(id = c(1,2,3,4,5), color1 = c("blue", "red",
"green", "blue", "orange"), color2 = c("orange", "green",
"blue", "red", "red"))
responses <- lapply( colordata2[ -1 ], function(col) { ifelse(col == 'blue', 1, 
0) } )
names(responses) <- names( colordata2 )[-1]

where each of the columns other than the first is handed in turn to the 
anonymous function that does the response calculation. The result is a data 
frame (list of columns) with no column names, so I give the new columns names 
based on the old column names. You could choose different names,  e.g.

names(responses) <- paste0( "response", 1:2 )

but you have to be careful to fix that code whenever you change the colordata2 
data frame to have more columns. 
-- 
Sent from my phone. Please excuse my brevity.

On April 7, 2016 4:57:04 AM PDT, Michael Artz  wrote:
>Thaks so much!  And how would you incorporate lapply() here?
>
>On Thu, Apr 7, 2016 at 6:52 AM, David Barron 
>wrote:
>
>> ifelse is vectorised, so just use that without the loop.
>>
>> colordata$response <- ifelse(colordata$color == 'blue', 1, 0)
>>
>> David
>>
>> On 7 April 2016 at 12:41, Michael Artz 
>wrote:
>>
>>> Hi I'm not sure how to ask this, but its a very easy question to
>answer
>>> for
>>> an R person.
>>>
>>> What is an easy way to check for a column value and then assigne a
>new
>>> column a value based on that old column value?
>>>
>>> For example, Im doing
>>>  colordata <- data.frame(id = c(1,2,3,4,5), color = c("blue", "red",
>>> "green", "blue", "orange"))
>>>  for (i in 1:nrow(colordata)){
>>>colordata$response[i] <- ifelse(colordata[i,"color"] == "blue",
>1, 0)
>>>  }
>>>
>>> which works,  but I don't want to use the for loop I want to
>"vecotrize"
>>> this.  How would this be implemented?
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

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


Re: [R] simple question on data frames assignment

2016-04-07 Thread PIKAL Petr
Hi

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Michael
> Artz
> Sent: Thursday, April 7, 2016 1:57 PM
> To: David Barron 
> Cc: r-help@r-project.org
> Subject: Re: [R] simple question on data frames assignment
>
> Thaks so much!  And how would you incorporate lapply() here?

Why do you want to use lapply? What is a result you want to achieve?

Actually color is factor and it has a numeric value "inside".

> as.numeric(colordata$color)
[1] 1 4 2 1 3

Cheers
Petr

>
> On Thu, Apr 7, 2016 at 6:52 AM, David Barron  wrote:
>
> > ifelse is vectorised, so just use that without the loop.
> >
> > colordata$response <- ifelse(colordata$color == 'blue', 1, 0)
> >
> > David
> >
> > On 7 April 2016 at 12:41, Michael Artz  wrote:
> >
> >> Hi I'm not sure how to ask this, but its a very easy question to
> >> answer for an R person.
> >>
> >> What is an easy way to check for a column value and then assigne a
> >> new column a value based on that old column value?
> >>
> >> For example, Im doing
> >>  colordata <- data.frame(id = c(1,2,3,4,5), color = c("blue", "red",
> >> "green", "blue", "orange"))  for (i in 1:nrow(colordata)){
> >>colordata$response[i] <- ifelse(colordata[i,"color"] == "blue", 1,
> >> 0)  }
> >>
> >> which works,  but I don't want to use the for loop I want to "vecotrize"
> >> this.  How would this be implemented?
> >>
> >> [[alternative HTML version deleted]]
> >>
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >
> >
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 

Re: [R] dynamic reports with sweave: error when compiling the tex-file

2016-04-07 Thread Jeff Newmiller
Did you really put spaces between the backslashes and the keywords? That would 
be a problem...
-- 
Sent from my phone. Please excuse my brevity.

On April 7, 2016 4:32:29 AM PDT, palad...@trustindata.de wrote:
>Hello,
>I took my first steps in dynamic reports with Gnu R and used sweave(). 
>
>I therefore run Sweave() with an example of Friedrich Leisch, starting 
>
>like this:
>
>\ documentclass [ a4paper ]{ article }
>\ title { Sweave Example 1}
>\ author { Friedrich Leisch }
>\ begin { document }
>\ maketitle
>and so on.
>
>It worked very well but when I tried to compile the latex file I get  
>this error message: ! LaTeX Error: Missing \begin{document}."
>
>
>But clearly there is a "begin{document}"
>
>I looked for a clue searching the internet and read that maybe my  
>editor writes invisible signs, so called boms, so that "\begin  
>{document} " is not really at the beginninng but these boms.
>
>Unfortunatly I have not the faintest how to solve the problem.
>
>(I am using GNU R 3.01 and windows10 and installed MiKTex.)
>
>It would be really nice if someone could help me!
>
>
>Best  regards and thanking you in anticipation.
>
>Claudia
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

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


Re: [R] Analyze a file

2016-04-07 Thread PIKAL Petr
Hi

myfile <- read.table("file.txt")
plot(myfile)

If it does not work, you have wrong file.txt

Cheers
Petr

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Mohamed
> Benahmed via R-help
> Sent: Thursday, April 7, 2016 11:27 AM
> To: r-help@r-project.org
> Subject: [R] Analyze a file
>
>
> hi all,How to analyze a file.txt with R to obtain the corresponding graph.What
> is the script ?
> Please help me!
> Thanks,
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the person represented by the 
recipient, or the existence of such authorization is known to the recipient of 
the person represented by the recipient.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Analyze a file

2016-04-07 Thread Mohamed Benahmed via R-help

hi all,How to analyze a file.txt with R to obtain the corresponding graph.What 
is the script ?
Please help me!
Thanks,
[[alternative HTML version deleted]]

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


[R] dynamic reports with sweave: error when compiling the tex-file

2016-04-07 Thread paladini

Hello,
I took my first steps in dynamic reports with Gnu R and used sweave().  
I therefore run Sweave() with an example of Friedrich Leisch, starting  
like this:


\ documentclass [ a4paper ]{ article }
\ title { Sweave Example 1}
\ author { Friedrich Leisch }
\ begin { document }
\ maketitle
and so on.

It worked very well but when I tried to compile the latex file I get  
this error message: ! LaTeX Error: Missing \begin{document}."



But clearly there is a "begin{document}"

I looked for a clue searching the internet and read that maybe my  
editor writes invisible signs, so called boms, so that "\begin  
{document} " is not really at the beginninng but these boms.


Unfortunatly I have not the faintest how to solve the problem.

(I am using GNU R 3.01 and windows10 and installed MiKTex.)

It would be really nice if someone could help me!


Best  regards and thanking you in anticipation.

Claudia

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

2016-04-07 Thread Michael Artz
Thaks so much!  And how would you incorporate lapply() here?

On Thu, Apr 7, 2016 at 6:52 AM, David Barron  wrote:

> ifelse is vectorised, so just use that without the loop.
>
> colordata$response <- ifelse(colordata$color == 'blue', 1, 0)
>
> David
>
> On 7 April 2016 at 12:41, Michael Artz  wrote:
>
>> Hi I'm not sure how to ask this, but its a very easy question to answer
>> for
>> an R person.
>>
>> What is an easy way to check for a column value and then assigne a new
>> column a value based on that old column value?
>>
>> For example, Im doing
>>  colordata <- data.frame(id = c(1,2,3,4,5), color = c("blue", "red",
>> "green", "blue", "orange"))
>>  for (i in 1:nrow(colordata)){
>>colordata$response[i] <- ifelse(colordata[i,"color"] == "blue", 1, 0)
>>  }
>>
>> which works,  but I don't want to use the for loop I want to "vecotrize"
>> this.  How would this be implemented?
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]

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


Re: [R] simple question on data frames assignment

2016-04-07 Thread David Barron
ifelse is vectorised, so just use that without the loop.

colordata$response <- ifelse(colordata$color == 'blue', 1, 0)

David

On 7 April 2016 at 12:41, Michael Artz  wrote:

> Hi I'm not sure how to ask this, but its a very easy question to answer for
> an R person.
>
> What is an easy way to check for a column value and then assigne a new
> column a value based on that old column value?
>
> For example, Im doing
>  colordata <- data.frame(id = c(1,2,3,4,5), color = c("blue", "red",
> "green", "blue", "orange"))
>  for (i in 1:nrow(colordata)){
>colordata$response[i] <- ifelse(colordata[i,"color"] == "blue", 1, 0)
>  }
>
> which works,  but I don't want to use the for loop I want to "vecotrize"
> this.  How would this be implemented?
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] simple question on data frames assignment

2016-04-07 Thread Michael Artz
Hi I'm not sure how to ask this, but its a very easy question to answer for
an R person.

What is an easy way to check for a column value and then assigne a new
column a value based on that old column value?

For example, Im doing
 colordata <- data.frame(id = c(1,2,3,4,5), color = c("blue", "red",
"green", "blue", "orange"))
 for (i in 1:nrow(colordata)){
   colordata$response[i] <- ifelse(colordata[i,"color"] == "blue", 1, 0)
 }

which works,  but I don't want to use the for loop I want to "vecotrize"
this.  How would this be implemented?

[[alternative HTML version deleted]]

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


Re: [R-es] Contenido de un objeto/modelo ARIMA

2016-04-07 Thread david santolaria
Le echo un vistazo, algo aprenderé seguro. Gracias!

El 7 de abril de 2016, 11:04, Isidro Hidalgo Arellano 
escribió:

> El autor del paquete es Hyndman, tiene un libro on-line en el que puedes
> echar un vistazo. La parte de modelos ARIMA en R está aquí:
> https://www.otexts.org/fpp/8/7
> Esos "TRUE" podrían significar que has utilizado coeficiente, deriva,
> media... no recuerdo exactamente los parámetros que utiliza la función.
> Un saludo
>
> Isidro Hidalgo Arellano
> Observatorio del Mercado de Trabajo
> Consejería de Economía, Empresas y Empleo
> http://www.castillalamancha.es/
>
>
>
> -Mensaje original-
> De: R-help-es [mailto:r-help-es-boun...@r-project.org] En nombre de david
> santolaria
> Enviado el: jueves, 07 de abril de 2016 10:54
> Para: r-help-es 
> Asunto: [R-es] Contenido de un objeto/modelo ARIMA
>
> Buenos días,
>
> Os cuento:
>
> Cargo la librería "Forecast" y ejecuto su función Arima(...) sobre una
> serie
> temporal:
>
> mimodelo <- Arima(miST$miserie, ...);
>
> Ahora si ejecuto las siguientes sentencias, voy obteniendo los resultados
> contenidos en "mimodelo", pero algunos de ellos no sé lo que son:
>
> mimodelo[[1]] obtengo los coeficientes del modelo ARIMA mimodelo[[2]]
> obtengo el sigma^2 mimodelo[[3]] obtengo la matriz de varianzas y covar de
> los coeficientes ...
>
> Pero por ejemplo: mimodelo[[4]] obtengo "true true true" y esto no tengo ni
> idea que es ¿significatividades?
>
> El caso es que en la documentación de la librería no explica nada de esto.
> ¿alguien sabe dónde o cómo se puede consultar?
>
> Gracias
> David
>
> [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
>

[[alternative HTML version deleted]]

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


Re: [R-es] Contenido de un objeto/modelo ARIMA

2016-04-07 Thread david santolaria
Perfecto!! Gracias. :)

El 7 de abril de 2016, 11:01, Carlos J. Gil Bellosta 
escribió:

> Hola, ¿qué tal?
>
> Copio de la ayuda de la función:
>
> library(forecast)
> fit <- Arima(WWWusage,order=c(3,1,0))
>
> names(fit)
> # [1] "coef"  "sigma2""var.coef"  "mask"  "loglik"
> # [6] "aic"   "arma"  "residuals" "call"  "series"
> # [11] "code"  "n.cond""nobs"  "model" "aicc"
> # [16] "bic"   "x"
>
> Esos son los componentes del objeto resultante. En la ayuda de ?Arima,
> en la sección "Value", explica qué son cada uno de ellos.
>
> Un saludo,
>
> Carlos J. Gil Bellosta
> http://www.datanalytics.com
>
>
>
> El día 7 de abril de 2016, 10:54, david santolaria
>  escribió:
> > Buenos días,
> >
> > Os cuento:
> >
> > Cargo la librería "Forecast" y ejecuto su función Arima(...) sobre una
> > serie temporal:
> >
> > mimodelo <- Arima(miST$miserie, ...);
> >
> > Ahora si ejecuto las siguientes sentencias, voy obteniendo los resultados
> > contenidos en "mimodelo", pero algunos de ellos no sé lo que son:
> >
> > mimodelo[[1]] obtengo los coeficientes del modelo ARIMA
> > mimodelo[[2]] obtengo el sigma^2
> > mimodelo[[3]] obtengo la matriz de varianzas y covar de los coeficientes
> > ...
> >
> > Pero por ejemplo: mimodelo[[4]] obtengo "true true true" y esto no tengo
> ni
> > idea que es ¿significatividades?
> >
> > El caso es que en la documentación de la librería no explica nada de
> esto.
> > ¿alguien sabe dónde o cómo se puede consultar?
> >
> > Gracias
> > David
> >
> > [[alternative HTML version deleted]]
> >
> > ___
> > R-help-es mailing list
> > R-help-es@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-help-es
>

[[alternative HTML version deleted]]

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


Re: [R-es] Contenido de un objeto/modelo ARIMA

2016-04-07 Thread Isidro Hidalgo Arellano
El autor del paquete es Hyndman, tiene un libro on-line en el que puedes
echar un vistazo. La parte de modelos ARIMA en R está aquí:
https://www.otexts.org/fpp/8/7
Esos "TRUE" podrían significar que has utilizado coeficiente, deriva,
media... no recuerdo exactamente los parámetros que utiliza la función.
Un saludo   

Isidro Hidalgo Arellano
Observatorio del Mercado de Trabajo
Consejería de Economía, Empresas y Empleo
http://www.castillalamancha.es/



-Mensaje original-
De: R-help-es [mailto:r-help-es-boun...@r-project.org] En nombre de david
santolaria
Enviado el: jueves, 07 de abril de 2016 10:54
Para: r-help-es 
Asunto: [R-es] Contenido de un objeto/modelo ARIMA

Buenos días,

Os cuento:

Cargo la librería "Forecast" y ejecuto su función Arima(...) sobre una serie
temporal:

mimodelo <- Arima(miST$miserie, ...);

Ahora si ejecuto las siguientes sentencias, voy obteniendo los resultados
contenidos en "mimodelo", pero algunos de ellos no sé lo que son:

mimodelo[[1]] obtengo los coeficientes del modelo ARIMA mimodelo[[2]]
obtengo el sigma^2 mimodelo[[3]] obtengo la matriz de varianzas y covar de
los coeficientes ...

Pero por ejemplo: mimodelo[[4]] obtengo "true true true" y esto no tengo ni
idea que es ¿significatividades?

El caso es que en la documentación de la librería no explica nada de esto.
¿alguien sabe dónde o cómo se puede consultar?

Gracias
David

[[alternative HTML version deleted]]

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

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


Re: [R-es] Contenido de un objeto/modelo ARIMA

2016-04-07 Thread Carlos J. Gil Bellosta
Hola, ¿qué tal?

Copio de la ayuda de la función:

library(forecast)
fit <- Arima(WWWusage,order=c(3,1,0))

names(fit)
# [1] "coef"  "sigma2""var.coef"  "mask"  "loglik"
# [6] "aic"   "arma"  "residuals" "call"  "series"
# [11] "code"  "n.cond""nobs"  "model" "aicc"
# [16] "bic"   "x"

Esos son los componentes del objeto resultante. En la ayuda de ?Arima,
en la sección "Value", explica qué son cada uno de ellos.

Un saludo,

Carlos J. Gil Bellosta
http://www.datanalytics.com



El día 7 de abril de 2016, 10:54, david santolaria
 escribió:
> Buenos días,
>
> Os cuento:
>
> Cargo la librería "Forecast" y ejecuto su función Arima(...) sobre una
> serie temporal:
>
> mimodelo <- Arima(miST$miserie, ...);
>
> Ahora si ejecuto las siguientes sentencias, voy obteniendo los resultados
> contenidos en "mimodelo", pero algunos de ellos no sé lo que son:
>
> mimodelo[[1]] obtengo los coeficientes del modelo ARIMA
> mimodelo[[2]] obtengo el sigma^2
> mimodelo[[3]] obtengo la matriz de varianzas y covar de los coeficientes
> ...
>
> Pero por ejemplo: mimodelo[[4]] obtengo "true true true" y esto no tengo ni
> idea que es ¿significatividades?
>
> El caso es que en la documentación de la librería no explica nada de esto.
> ¿alguien sabe dónde o cómo se puede consultar?
>
> Gracias
> David
>
> [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es

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


Re: [R] identifying outliers

2016-04-07 Thread PIKAL Petr
Hi

You can check boxplot output by str

> iris[1,1] <- 10
> iris[2,1] <- 8
> bbb <- boxplot(split(iris[,1], iris$Species))
> str(bbb)
List of 6
 $ stats: num [1:5, 1:3] 4.3 4.8 5 5.3 5.8 4.9 5.6 5.9 6.3 7 ...
 $ n: num [1:3] 50 50 50
 $ conf : num [1:2, 1:3] 4.89 5.11 5.74 6.06 6.34 ...
 $ out  : num [1:3] 10 8 4.9
 $ group: num [1:3] 1 1 3
 $ names: chr [1:3] "setosa" "versicolor" "virginica"
>
and you can find that result is list with out vector containing all outliers 
and group vector of indication to which group outliers belong.

Getting the output depends on what you want to do with it.

Cheers
Petr

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Thomas
> Subia via R-help
> Sent: Thursday, April 7, 2016 6:10 AM
> To: r-h...@stat.math.ethz.ch
> Subject: [R] identifying outliers
>
> Thanks for writing this great piece of code.
>
>
>
> x = rnorm(100)
>
> boxplot(x) # you shouldn't see any outliers here although sometimes yow
> will
>
>
>
> # lets add some outliers intentionally
>
> x = c(21, 20, 25, x) # now 10, 15 and 20 are outliers
>
>
>
> myboxplot <- boxplot(x) # now you should see your three outliers
>
>
>
> myboxplot$out # it will print the values of the outliers
>
>
>
> How does one amend this code to produce the outliers by a group?
>
>
>
> All the best,
>
>
>
> Thomas Subia
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the person represented by the 
recipient, or the existence of such authorization is known to the recipient of 
the person represented by the recipient.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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-es] Contenido de un objeto/modelo ARIMA

2016-04-07 Thread david santolaria
Buenos días,

Os cuento:

Cargo la librería "Forecast" y ejecuto su función Arima(...) sobre una
serie temporal:

mimodelo <- Arima(miST$miserie, ...);

Ahora si ejecuto las siguientes sentencias, voy obteniendo los resultados
contenidos en "mimodelo", pero algunos de ellos no sé lo que son:

mimodelo[[1]] obtengo los coeficientes del modelo ARIMA
mimodelo[[2]] obtengo el sigma^2
mimodelo[[3]] obtengo la matriz de varianzas y covar de los coeficientes
...

Pero por ejemplo: mimodelo[[4]] obtengo "true true true" y esto no tengo ni
idea que es ¿significatividades?

El caso es que en la documentación de la librería no explica nada de esto.
¿alguien sabe dónde o cómo se puede consultar?

Gracias
David

[[alternative HTML version deleted]]

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


Re: [R] Problem with <= (less than or equal): not giving the expected result

2016-04-07 Thread PIKAL Petr
Hi

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of S Ellison
> Sent: Wednesday, April 6, 2016 12:35 PM
> To: Rainer Johannes ; r-help@r-project.org
> Subject: Re: [R] Problem with <= (less than or equal): not giving the expected
> result
>
> > Apparently, abs(1 - 0.95) is not equal to 0.05, which I find however
> > quite disturbing.
>
> It's normal.* See R FAQ 7.31 in the html help system.
>
> S Ellison
>
> *... and common to all computers that use binary.

The main issue is that when using Excel you do not experience normally such 
issues, probably because Excel silently decide how to express precision of 
decimal values.

=+ABS(1-0.995) is equal to 0.005, however
=+ABS(1-0.9995) is not equal to 0.0005

So it when Excel (Excel 2016) users do not use numbers smaller than 0.005 they 
do not find this behaviour.

Cheers
Petr



>
>
>
> **
> *
> This email and any attachments are confidential. Any use, copying or
> disclosure other than by the intended recipient is unauthorised. If you have
> received this message in error, please notify the sender immediately via
> +44(0)20 8943 7000 or notify postmas...@lgcgroup.com and delete this
> message and any copies from your computer and network.
> LGC Limited. Registered in England 2991879.
> Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the person represented by the 
recipient, or the existence of such authorization is known to the recipient of 
the person represented by the recipient.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, 

Re: [R] Memory problem

2016-04-07 Thread Amelia Marsh
Dear Sir,


Yes I am using the plyr and in the end I am writing the output to the 
data.frame. Earlier I had the problem of process time and hence I made some 
changes in the code and now I am fetching all the required inputs needed for 
valuation purpose using ddply, store the results in a data.frame and once that 
is over, I am carrying out the calculations.

Here is part of my R code-


library(plyr)
library(reshape)


tx <- read.csv('transaction_fxdeal.csv')
tx$id  <-  as.character(tx$id)

n<- max(unique(simulated_exchange$id))

result <- NULL
current  <- 1
rcount   <- 0
current1 <- 1
rcount1  <- 0
current2 <- 1
rcount2  <- 0
for (env in 0:n) {
  
  if (rcount == 0) rcount <- nrow(subset(simulated_interest, id==env))
  temp <- current+rcount-1
  env_rates  <- simulated_interest[current:temp,]
  env_rates  <- env_rates[order(env_rates$curve, env_rates$day_count), ]
  if (rcount1 == 0)rcount1 <- nrow(subset(simulated_exchange, id==env))
  temp <- current1+rcount1-1
  exch_rates <- simulated_exchange[current1:temp,]
  if (rcount2 == 0)rcount2 <- nrow(subset(simulated_instruments, id==env))
  temp <- current2+rcount2-1
  instr_rates<- simulated_instruments[current2:temp,]
  current <- current+rcount
  current1 <- current1+rcount1
  current2 <- current2+rcount2
  
  curve   <- daply(env_rates, 'curve', function(x) {
return(approxfun(x$day_count, x$rate, rule = 2))
  })
  
result <- rbind(result, ddply(tx, 'id', function(x) {

intrate_from <- curve[[x$currency_from]](x$maturity_from)
intrate_to   <- curve[[x$currency_to]](x$maturity_to)
cross_rate   <- subset(exch_rates, key==paste(x$currency_from_exch, 
x$currency_to_exch, sep='_'))$rate
base_rate<- subset(exch_rates, key==paste(x$currency_to_exch, 
x$currency_base, sep='_'))$rate

return(data.frame(env=env, intrate_from=intrate_from, intrate_to=intrate_to, 
cross_rate=cross_rate, base_rate=base_rate))


  }))
}

sorted <- result[order(result$id, result$env),]

sorted$currency_from_exch <- rep(tx$currency_from_exch, each = 
length(unique(sorted$env)))
sorted$currency_to_exch <- rep(tx$currency_to_exch, each = 
length(unique(sorted$env)))
sorted$currency_base <- rep(tx$currency_base, each = length(unique(sorted$env)))
sorted$transaction_type <- rep(tx$transaction_type, each = 
length(unique(sorted$env)))
sorted$amount_fromccy <- rep(tx$amount_fromccy, each = 
length(unique(sorted$env)))
sorted$amount_toccy <- rep(tx$amount_toccy, each = length(unique(sorted$env)))
sorted$intbasis_fromccy <- rep(tx$intbasis_fromccy, each = 
length(unique(sorted$env)))
sorted$intbasis_toccy <- rep(tx$intbasis_toccy, each = 
length(unique(sorted$env)))
sorted$maturity_from <- rep(tx$maturity_from, each = length(unique(sorted$env)))
sorted$maturity_to <- rep(tx$maturity_to, each = length(unique(sorted$env)))
sorted$currency_from <- rep(tx$currency_from, each = 
length(unique(sorted$env))) 
sorted$currency_to <- rep(tx$currency_to, each = length(unique(sorted$env))) 

sorted$from_mtm <- sorted$cross_rate * (sorted$amount_fromccy / ((1 + 
(sorted$intrate_from/100))^(sorted$maturity_from / sorted$intbasis_fromccy)))

sorted$to_mtm   <- (sorted$amount_toccy   / ((1 + 
(sorted$intrate_to/100))^(sorted$maturity_to / sorted$intbasis_toccy)))

mtm_base <- function(from_mtm, to_mtm, base_rate)
{
mtm <- (from_mtm + to_mtm)
mtm_bc = mtm*base_rate[1]

return(data.frame(mtm_bc = mtm_bc))
}

sorted1 <- ddply(.data=sorted, .variables = "id", .fun=function(x) 
mtm_base(from_mtm = x$from_mtm, to_mtm = x$to_mtm, base_rate = x$base_rate))

sorted$mtm <- sorted1$mtm
sorted$mtm_bc <- sorted1$mtm_bc

sorted2 <- ddply(sorted, .(currency_from_exch, id), mutate, change_in_mtm_bc = 
mtm_bc - mtm_bc[1])

sorted$change_in_mtm_bc <- sorted2$change_in_mtm_bc

sorted <- sorted[order(sorted$id, sorted$env),]

write.csv(data.frame(sorted), file='MC_result_fxdeal.csv', row.names=FALSE)

# 

# END of Code



With regards

Amelia







On Wednesday, 6 April 2016 7:43 PM, Jeff Newmiller  
wrote:



As Jim has indicated, memory usage problems can require very specific 
diagnostics and code changes,  so generic help is tough to give. 

However, in most cases I have found the dplyr package to be more memory 
efficient than plyr, so you could consider that. Also, you can be explicit 
about only saving the minimum results you want to keep rather than making a 
list of complete results and extracting results later. 
-- 
Sent from my phone. Please excuse my brevity.


On April 6, 2016 4:39:59 AM PDT, Amelia Marsh via R-help  
wrote:
Dear R Forum,
>
>I have about 2000+ FX forward transactions and I am trying to run 1000 
>simulations. If I use less no of simulations, I am able to get the desired 
>results. However, when I try to use more than 1000 simulations, I get 
>following error.
>
>
>sorted2 <- ddply(sorted, .(currency_from_exch, id), mutate, change_in_mtm_bc = 
>mtm_bc - mtm_bc[1]) 
>>

[R] identifying outliers

2016-04-07 Thread Thomas Subia via R-help
Thanks for writing this great piece of code.

 

x = rnorm(100)

boxplot(x) # you shouldn't see any outliers here although sometimes yow will

 

# lets add some outliers intentionally

x = c(21, 20, 25, x) # now 10, 15 and 20 are outliers

 

myboxplot <- boxplot(x) # now you should see your three outliers

 

myboxplot$out # it will print the values of the outliers

 

How does one amend this code to produce the outliers by a group?

 

All the best,

 

Thomas Subia


[[alternative HTML version deleted]]

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