[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 simulate

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`.

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 w

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["Cu

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

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 c

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 dat

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 yo

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)

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:5

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

[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]] __

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 o

[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.

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 th

[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

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 > fr

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ó: >

[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 data5NonEventsE

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 JA

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

[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.rajamoor

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." -

[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[

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 answe

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.

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.

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 <- lapp

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 Ap

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

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

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

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 th

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.

[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.c

[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 an

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 wrot

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 che

[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",

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

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 > > > Apparen