Re: [R] working on a data frame

2014-07-27 Thread PIKAL Petr
Hi I like to use logical values directly in computations if possible. yourData[,10] <- yourData[,9]/(yourData[,8]+(yourData[,8]==0)) Logical values are automagicaly considered FALSE=0 and TRUE=1 and can be used in computations. If you really want to change 0 to 1 in column 8 you can use yourDa

[R] Is there a package for EFA with multiple groups?

2014-07-27 Thread Elizabeth Barrett-Cheetham
Hello R users, I’m hoping to run an exploratory and confirmatory factor analysis on a psychology survey instrument. The data has been collected from multiple groups, and it’s likely that the data is hierarchical/has 2nd order factors. It appears that the lavaan package allows me to run a multiple

Re: [R] How to modify the body of a function?

2014-07-27 Thread Richard M. Heiberger
Now THAT is a fortune: My preferences are colored by my experience looking for problems in other people's code. My own code is always easy to understand but code other people write can be difficult. :-) On Sun, Jul 27, 2014 at 8:38 PM, William Dunlap wrote: > The problem with Don's > if (cond

Re: [R] function that join my model & these coefficients

2014-07-27 Thread Jim Lemon
On Sun, 27 Jul 2014 02:08:25 AM Maede Nouri wrote: > hello > I am new to R language. I fitted a linear model and my output has about 300 > coefficients. I need to definition a function that join my model & these > coefficients ! this is difficult because number of coefficients is many. I > thi

Re: [R] (no subject)

2014-07-27 Thread Jim Lemon
On Sun, 27 Jul 2014 01:41:51 AM kafi dano wrote: > Hi. I have a problem in R. I want the command of least median squares and > the package of this estimator > > Hi Kafi, Try the MASS (lmsreg) and robust packages. Jim __ R-help@r-project.org mailing l

[R] A quesion about Shiny

2014-07-27 Thread super
I now have two win7s in a local area network called A and B. A now can run shiny app, and it shows that it listen 192.168.1.100:6271. And A can visite the app in A's own chrome using 192.168.1.100:6271. Then I want to B to visite A's shiny app. I type 192.168.1.100:6271 in chrome, but it doesn

Re: [R] How to modify the body of a function?

2014-07-27 Thread Spencer Graves
On 7/27/2014 8:03 PM, super wrote: Tks for your opinions, let me describe the background for my question: The orignal purpose is to call the function which defined in anothor function, e.g. f1<-function(){ x<-1 f2<-function(x) {x} f3<-function(){ 1+1 } a<-1 return(x+a) } The real function f1 m

Re: [R] How to modify the body of a function?

2014-07-27 Thread super
Tks for your opinions, let me describe the background for my question: The orignal purpose is to call the function which defined in anothor function, e.g. f1<-function(){ x<-1 f2<-function(x) {x} f3<-function(){ 1+1 } a<-1 return(x+a) } The real function f1 may be very long, And i know there is

Re: [R] How to modify the body of a function?

2014-07-27 Thread William Dunlap
The problem with Don's if (condition) { Results <- something } else { Results <- somethingElse } is that in a long sequence of if-then-else-if... you have to check every branch to make sure Results got assigned to (or that the remaining branches contained a return() or a stop()).

Re: [R] How to modify the body of a function?

2014-07-27 Thread Spencer Graves
On 7/27/2014 4:29 PM, MacQueen, Don wrote: As long as people are sharing their preferences . . . I find return() useful in a scenario like the following: Myfun <- function() { {a few lines of code} if (condition) return(whatever) {Many, many lines of code} Results } Which I find p

Re: [R] How to modify the body of a function?

2014-07-27 Thread Duncan Murdoch
On 27/07/2014, 7:29 PM, MacQueen, Don wrote: > As long as people are sharing their preferences . . . > > > I find return() useful in a scenario like the following: > > Myfun <- function() { > {a few lines of code} > if (condition) return(whatever) > {Many, many lines of code} > Results >

Re: [R] How to modify the body of a function?

2014-07-27 Thread MacQueen, Don
As long as people are sharing their preferences . . . I find return() useful in a scenario like the following: Myfun <- function() { {a few lines of code} if (condition) return(whatever) {Many, many lines of code} Results } Which I find preferable to Myfun <- function() { { a few lin

Re: [R] How to modify the body of a function?

2014-07-27 Thread Bert Gunter
Just an (ignorable) opinion I'm not sure I would agree on the exception handling view, but maybe it often boils down to: Do you prefer: a) function(...) { if(cond1) {do one} else{ if(cond2) {do two}} else { if(cond3) {do three}} results } ## versus b) function(...) { if(cond1) {do one; ret

[R] (no subject)

2014-07-27 Thread kafi dano
Hi. I have a problem in R. I want the command of least median squares and the package of this estimator   Kafi Dano Pati Ph.D candidate ( mathematics/statistics) Department of mathematical Science/ faculty of Science University Technology Malaysia 81310 UTM, Johor Bahru, Johor, Malaysia H

Re: [R] How to modify the body of a function?

2014-07-27 Thread Jeff Newmiller
Well, he did say it was his opinion. Goto has been pretty effectively eliminated from modern programming languages, while return has not. IMHO the nature of the return statement resembles exception handling more than normal control flow... so I avoid using it. Exceptions are exceptional, and no

Re: [R] How to modify the body of a function?

2014-07-27 Thread Spencer Graves
On 7/27/2014 10:34 AM, William Dunlap wrote: This is a real hack, but you can redefine return in your function: f <- function() { + return("early return") + "last value in function" + } f() [1] "early return" f <- function() { + return <- function(x)x + return("early return"

Re: [R] How to modify the body of a function?

2014-07-27 Thread William Dunlap
This is a real hack, but you can redefine return in your function: > f <- function() { + return("early return") + "last value in function" + } > f() [1] "early return" > f <- function() { + return <- function(x)x + return("early return") + "last value in function" + } > f() [1]

Re: [R] How to modify the body of a function?

2014-07-27 Thread super
i try this to remove the "return" statement in the body(f): tmp<-as.character(body(f)) a<-sub("return","#return",tmp) but i don't know how to transfer the character form back to call form or language form or expression form ? Is the method i posted could be implemented correctly, or Is there oth

Re: [R] incorrect correlation coefficients

2014-07-27 Thread Patrick Burns
If the argument to the function you give in the 'by' call were 'z' instead of 'x', then it would have been easier to see what was wrong. You are using 'xx' inside the function rather than 'x'. I think you want something like: function(z) {cor(z$Data1.MEAN, z$Data2.MEAN)} Pat On 27/07/2014

Re: [R] function that join my model & these coefficients

2014-07-27 Thread Jeff Newmiller
You should study the theory of regression before proceeding, since the chance of obtaining a significant (useful) result with 400 inputs is negligible. You should also read the help files for the functions you are using (e.g. ?lm), which in this case mention the coef() function in the See Also s

Re: [R] How to modify the body of a function?

2014-07-27 Thread William Dunlap
I find bquote() handy for this sort of manipulation. E.g., > f <- function() { 1 } > origBody <- body(f) > newBody <- bquote({ .(origBody) ; .(addedStuff) }, list(origBody=origBody, > addedStuff=quote(function(){}))) > body(f) <- newBody > f function () { { 1 } function() {

[R] incorrect correlation coefficients

2014-07-27 Thread Mateusz Kędzior
Hello all, I strongly believe, that my issue is quite easy to resolve. However, I have no idea how to find/debug what is wrong and I would blame myself for insufficient knowledge about data tables and some useful functions in R! as apply, sapply, lapply. My question is as follows: I would like t

Re: [R] How to modify the body of a function?

2014-07-27 Thread Uwe Ligges
On 27.07.2014 15:41, super wrote: Suppose that I had a function as below: f<-function() { return(1) } i want to change the body of f to the form like this: f<-function(){ 1 function() {} } How can i do the task using body(f) or something else solutions? See ?body: body(f) <- as.call(c(as.n

[R] function that join my model & these coefficients

2014-07-27 Thread Maede Nouri
hello  I am new to R language. I fitted a linear model and my output has about 300 coefficients. I need to definition a function that join my model & these coefficients ! this is difficult because number of coefficients is many.  I think there is not a provided query for this. I also used "fitted

[R] How to modify the body of a function?

2014-07-27 Thread super
Suppose that I had a function as below: f<-function() { return(1) } i want to change the body of f to the form like this: f<-function(){ 1 function() {} } How can i do the task using body(f) or something else solutions? [[alternative HTML version deleted]]

Re: [R] Correlation

2014-07-27 Thread Rui Barradas
Hello, If I understand it correctly the following should do it. Note that it removes both columns and rows. idx <- corData > 0.5 diag(idx) <- FALSE idx2 <- which(apply(idx, 2, function(x) !any(x))) corData[-idx2, -idx2] Use corData[, -idx2] to remove only columns. Hope this helps, Rui Bar

[R] Correlation

2014-07-27 Thread Nico Met
Dear all, I have written the following code for correlation calculations. I want to create a new matrix from corData) with correlation more than 0.5 only and the rest of the columns should be removed. How can I do it? set.seed(1234) data<-matrix(rnorm(100),nrow=10) data[,1]<-100*(data[,2]+data[