Re: [R] MCP solver
Maxwell, John McFarland jmmaxwell at wsu.edu writes: Hello, I'm trying to find a solver that will work for the mixed complementarity problem (MCP). I've searched the CRAN task view page on optimization and mathematical programming as well as many google searches to no avail. Does anyone know if there is an MCP solver available for R? Thanks very much, JM The problem class of 'mixed complementary problems' is quite big and encompasses difficult optimization problems such as nonlinear systems of equations, nonlinear optimization problems, or optimization with equality constraints, among others. There is no solver or package in R that will solve 'mixed complementary problems' in general. Perhaps your problem can be cast into a more specialized form that is accessible to one of the available solvers. Otherwise, GAMS has its own module for solving MCP problems. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Hungarian R User's Group: ggplot2 - The Grammar of Graphics
Dear useRs, I am more than happy to announce the next meeting of the Hungarian RUG that will take place on the 24th of October, and Zoltán Tóth, senior data engineer at Prezi.com, will speak about Hadley's awesome ggplot2 package. More details (HUN): http://www.meetup.com/Budapest-Users-of-R-Network/events/142204572/ Come and visit the Budapest Users of R Network and beside listening to interesting talks, join us for this rather socializing event and meet other R users living in Hungary! And have some pizzas and drinks paid by our sponsors :) See you soon, best, Gergely [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] lmerTest
On 13.10.2013 02:52, srecko joksimovic wrote: ok, ok... thanks. I'll try with R-sig-ME Or for short, you are trying to estimate more coefficients than you have degrees of freedom which is what rank of X = 1660 ncol(X) = 1895 tries to tell us. Best, Uwe Ligges On Sat, Oct 12, 2013 at 5:43 PM, Jeff Newmiller jdnew...@dcn.davis.ca.uswrote: Any idea what could be the problem? Hmmm... posting in html? No reproducible example? Not posting on R-sig-ME? Just some ideas... reading the Posting Guide might be helpful to you. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. srecko joksimovic sreckojoksimo...@gmail.com wrote: Hi, I'm trying to user lmer function from lmerTest package because, if I understood correectly, it allows to make better inference than lmer method from lme4 package. However, whatever I do I keep getting this error: Error in lme4::lFormula(formula = mark ~ ssCount + sTime+ : rank of X = 1660 ncol(X) = 1895 any ideas what could be a problem? thanks, Srecko [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] matrix values linked to vector index
Just a further suggestion: vec - c(3,2,5,0,1) mat - t(sapply(vec,=,1:max(vec))) ifelse(mat,1,0) Cheers, Christoph 2013/10/11 arun smartpink...@yahoo.com: Hi, In the example you showed: m1- matrix(0,length(vec),max(vec)) 1*!upper.tri(m1) #or m1[!upper.tri(m1)] - rep(rep(1,length(vec)),vec) #But, in a case like below, perhaps: vec1- c(3,4,5) m2- matrix(0,length(vec1),max(vec1)) indx - cbind(rep(seq_along(vec1),vec1),unlist(tapply(vec1,list(vec1),FUN=seq),use.names=FALSE)) m2[indx]- 1 m2 # [,1] [,2] [,3] [,4] [,5] #[1,]11100 #[2,]11110 #[3,]11111 A.K. Hi- I'd like to create a matrix of 0's and 1's where the number of 1's in each row defined by the value indexed in another vector, and where the (value-1) is back-filled by 0's. For example, given the following vector: vec= c(1,2,3) I'd like to produce a matrix with dimensions (length(vec), max(vec)): 1,0,0 1,1,0 1,1,1 Thank you! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] matrix values linked to vector index
Also: mat+0 #or mat*1 #However, sapply() based solutions would be slower in large matrices. #Speed makeMat3 - function(x,n){ if(is.numeric(x)){ x - as.integer(round(x)) x} stopifnot(is.integer(x)) if(length(x)=n max(x)=n){ indx-rep(rep(c(1,0),max(length(x),n)),rbind(x,n-x)) m1- matrix(indx,nc=n,byr=TRUE) } else if(length(x) n) { indx-rep(rep(c(1,0),n),c(as.vector(rbind(x,n-x)),rep(c(0,n),n-length(x m1-matrix(indx[seq_len(length(indx)-(n*(n-length(x],nc=n,byr=TRUE) } else print(paste(Not possible: Number of columns less than the maximum value of , max(x), or length of vector)) m1 } set.seed(124) xtest- sample(0:9,1e7,replace=TRUE) system.time(res3- makeMat3(xtest,9)) # user system elapsed # 2.000 0.528 2.533 system.time({res4- t(sapply(xtest,=,1:max(xtest))) res4- res4*1}) # user system elapsed # 42.648 0.728 43.461 identical(res3,res4) #[1] TRUE A.K. On Sunday, October 13, 2013 3:55 AM, Christoph Häni ch.ha...@gmail.com wrote: Just a further suggestion: vec - c(3,2,5,0,1) mat - t(sapply(vec,=,1:max(vec))) ifelse(mat,1,0) Cheers, Christoph 2013/10/11 arun smartpink...@yahoo.com: Hi, In the example you showed: m1- matrix(0,length(vec),max(vec)) 1*!upper.tri(m1) #or m1[!upper.tri(m1)] - rep(rep(1,length(vec)),vec) #But, in a case like below, perhaps: vec1- c(3,4,5) m2- matrix(0,length(vec1),max(vec1)) indx - cbind(rep(seq_along(vec1),vec1),unlist(tapply(vec1,list(vec1),FUN=seq),use.names=FALSE)) m2[indx]- 1 m2 # [,1] [,2] [,3] [,4] [,5] #[1,] 1 1 1 0 0 #[2,] 1 1 1 1 0 #[3,] 1 1 1 1 1 A.K. Hi- I'd like to create a matrix of 0's and 1's where the number of 1's in each row defined by the value indexed in another vector, and where the (value-1) is back-filled by 0's. For example, given the following vector: vec= c(1,2,3) I'd like to produce a matrix with dimensions (length(vec), max(vec)): 1,0,0 1,1,0 1,1,1 Thank you! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] lmerTest
Thanks Uwe, I wasn't quite sure about that one... when I build model with that particular variable, that is what happen. have to check why... Best, Srecko On Sun, Oct 13, 2013 at 5:45 AM, Uwe Ligges lig...@statistik.tu-dortmund.de wrote: On 13.10.2013 02:52, srecko joksimovic wrote: ok, ok... thanks. I'll try with R-sig-ME Or for short, you are trying to estimate more coefficients than you have degrees of freedom which is what rank of X = 1660 ncol(X) = 1895 tries to tell us. Best, Uwe Ligges On Sat, Oct 12, 2013 at 5:43 PM, Jeff Newmiller jdnew...@dcn.davis.ca.us **wrote: Any idea what could be the problem? Hmmm... posting in html? No reproducible example? Not posting on R-sig-ME? Just some ideas... reading the Posting Guide might be helpful to you. --**--** --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --**--** --- Sent from my phone. Please excuse my brevity. srecko joksimovic sreckojoksimo...@gmail.com wrote: Hi, I'm trying to user lmer function from lmerTest package because, if I understood correectly, it allows to make better inference than lmer method from lme4 package. However, whatever I do I keep getting this error: Error in lme4::lFormula(formula = mark ~ ssCount + sTime+ : rank of X = 1660 ncol(X) = 1895 any ideas what could be a problem? thanks, Srecko [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/**posting-guide.htmlhttp://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 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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 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] [Urgent]replace several rows in matrix with a vector
Hi, Try: a - matrix(0,100,3) a1- a a2 - a somerows- 1:5 b1- t(replicate(length(somerows),b)) a[somerows,]- b1 head(a) #or b2- rep(b,each=length(somerows)) a1[somerows,]- b2 head(a1) identical(a,a1) #[1] TRUE somerows2- c(2,4,7,8,11,14) b3 - rep(b,each=length(somerows2)) a2[somerows2,] - b3 head(a2,15) A.K. hi all, what i want to ask is how to replace rows with a vetor without looping. for example, I have one matrix like this, a-matrix(0,100,3) and then, I want to replace some of rows with this vector, b-c(1,2,3) when I use below code, the result is what I want, a[somerows,]-t(b) result of a[somerows,] is 1 2 1 2 3 2 3 1 3 1 2 1 2 3 2 3 1 3 1 2 1 actually I want this format below, 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 how can I solve this problem? Thanks, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] RODBC not connecting from my Mac
iODBC appears no longer to come standard with OSX, so I installed unixodbc and set it up following instructions here: http://www.boriel.com/en/2013/01/16/postgresql-odbc-connection-from-mac-os-x/ I connected to my remote database with isql -v mydsn. No problem. Then I tried from R: library(RODBC) pg - odbcConnect(mydsn) # waited for a couple of minutes before pressing Ctrl-C ^C There were 50 or more warnings (use warnings() to see the first 50) warnings()[1:2] Warning messages: 1: In odbcDriverConnect(DSN=mydsn) : [RODBC] ERROR: state IM002, code 1606406032, message [iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded 2: In odbcDriverConnect(DSN=mydsn) : [RODBC] ERROR: state IM002, code 1606406032, message [iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded It looks like RODBC might only work with iODBC on the Mac. Is that the case? I haven't been able to configure iODBC correctly, and therefore haven't been able to test whether that would work with RODBC. Any chance that I can get RODBC to work with unixodbc? Any other information that would be useful in resolving it? sessionInfo() R version 3.0.2 (2013-09-25) Platform: x86_64-apple-darwin10.8.0 (64-bit) locale: [1] C/UTF-8/C/C/C/C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] RODBC_1.3-8 Regards Mikkel [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How can I use a script l (LaTeX \ell) in mathematical annotation of plots?
Due to convention a script l - $$\ell$$ (LaTeX \ell) is used to represent a certain quantity in something I'm working on. I'm unable to figure out how to use it in R. It's not included in the list on ?plotmath. Can anyone tell me how to use it? Its unicode is U+2113. This page has a list of various encodings of it: http://www.fileformat.info/info/unicode/char/2113/encoding.htm. Is there a way to include it by using one of these encodings somehow? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How can I use a script l (LaTeX \ell) in mathematical annotation of plots?
On 13/10/2013 18:53, Byron Dom wrote: Due to convention a script l - $$\ell$$ (LaTeX \ell) is used to represent a certain quantity in something I'm working on. I'm unable to figure out how to use it in R. It's not included in the list on ?plotmath. Can anyone tell me how to use it? Its unicode is U+2113. This page has a list of various encodings of it: http://www.fileformat.info/info/unicode/char/2113/encoding.htm. Is there a way to include it by using one of these encodings somehow? [[alternative HTML version deleted]] What do you want to do with it? plotmath is about plotting, but you have not otherwise mentioned that, let alone the device on which you want to plot. Read the help for plotmath: on some plot devices, just use \u2113. It is not AFAICS in the Adobe symbol encoding. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] using a variable for a column name in a formula
lm(height ~ ., data=X) works fine. However nnn - height ; lm(nnn ~ . ,data=X) fails How do I write such a formula, which depends on the value of a string variable like nnn above? A typical application might be a program that takes a data frame containing only numerical data, and figures out which of the columns can be best predicted from all the other columns. Thanks David __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using a variable for a column name in a formula
This being R, there are likely other ways, but I use: lm(as.formula(paste(nnn, ~ .)),data=X) Sarah On Sun, Oct 13, 2013 at 5:04 PM, David Epstein david.epst...@warwick.ac.uk wrote: lm(height ~ ., data=X) works fine. However nnn - height ; lm(nnn ~ . ,data=X) fails How do I write such a formula, which depends on the value of a string variable like nnn above? A typical application might be a program that takes a data frame containing only numerical data, and figures out which of the columns can be best predicted from all the other columns. Thanks David -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using a variable for a column name in a formula
Hi, May be: set.seed(24) X - data.frame(weight=sample(100:250,20,replace=TRUE),height=sample(140:190,20,replace=TRUE)) Others - colnames(X)[!colnames(X)%in%height] nnn - height res - lm(formula(paste(nnn,~,paste(Others, sep=+))),data=X) res1- lm(height~.,data=X) #or res2- lm(get(nnn)~get(Others),data=X) #needs some renaming of rownames identical(coef(summary(res)),coef(summary(res1))) #[1] TRUE A.K. On Sunday, October 13, 2013 5:06 PM, David Epstein david.epst...@warwick.ac.uk wrote: lm(height ~ ., data=X) works fine. However nnn - height ; lm(nnn ~ . ,data=X) fails How do I write such a formula, which depends on the value of a string variable like nnn above? A typical application might be a program that takes a data frame containing only numerical data, and figures out which of the columns can be best predicted from all the other columns. Thanks David __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using a variable for a column name in a formula
Sorry, a mistake in the code: #should be collapse instead of sep res - lm(formula(paste(nnn,~,paste(Others, collapse=+))),data=X) A.K. On Sunday, October 13, 2013 5:55 PM, arun smartpink...@yahoo.com wrote: Hi, May be: set.seed(24) X - data.frame(weight=sample(100:250,20,replace=TRUE),height=sample(140:190,20,replace=TRUE)) Others - colnames(X)[!colnames(X)%in%height] nnn - height res - lm(formula(paste(nnn,~,paste(Others, sep=+))),data=X) res1- lm(height~.,data=X) #or res2- lm(get(nnn)~get(Others),data=X) #needs some renaming of rownames identical(coef(summary(res)),coef(summary(res1))) #[1] TRUE A.K. On Sunday, October 13, 2013 5:06 PM, David Epstein david.epst...@warwick.ac.uk wrote: lm(height ~ ., data=X) works fine. However nnn - height ; lm(nnn ~ . ,data=X) fails How do I write such a formula, which depends on the value of a string variable like nnn above? A typical application might be a program that takes a data frame containing only numerical data, and figures out which of the columns can be best predicted from all the other columns. Thanks David __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using a variable for a column name in a formula
On 2013-10-14 10:04, David Epstein wrote: lm(height ~ ., data=X) works fine. However nnn - height ; lm(nnn ~ . ,data=X) fails How do I write such a formula, which depends on the value of a string variable like nnn above? as.formula() with paste() could work, but from where you are now, try lm(get(nnn) ~ . ,data=X) HTH A typical application might be a program that takes a data frame containing only numerical data, and figures out which of the columns can be best predicted from all the other columns. Thanks David __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loop over factor returns NA
You'll need to tell us what class you time variable is in, e.g. the output of str(AB), but the following might work: for (i in unique(as.character(AB$time)) { Intervall - AB[as.character(AB$time) ==i, ] ... } Depending on the format, as.numeric( ) might work too. Regards Mikkel On Saturday, October 12, 2013 12:16 PM, anna berg anna.berg1...@hotmail.com wrote: Dear R users, I am pretty new to programming in R. So I guess there is some obvious mistake I am making. I hope you can help me. I have a data frame that looks like this: AB time x y z gene part 1 03:27:58 1 2 3 grom 1 2 03:27:58 2 3 4 grom 1 3 03:27:58 3 4 5 grom 1 4 04:44:23 12 13 14 grom 2 5 04:44:23 13 14 15 grom 2 6 04:44:23 14 15 16 grom 2 7 04:44:23 15 16 17 grom 2 8 06:23:45 101 102 103 vir 3 9 06:23:45 102 103 104 vir 3 10 06:23:45 103 104 105 vir 3 Now I want to apply a loop (here a simplified version; I know that I could do this easily with tapply, but for the other things that I want to do with the loop (e.g. weighted mean of time series after fast fourier transformation) I would rather like to use a loop). Note that time and part are actually the same, just one is a factor and the the other is a number. Here is the loop that works fine and returns the result as I want (the important part here is: Intervall - AB[AB$part==i,]): for(i in 1:length(unique(AB$time))) { Intervall - AB[AB$part==i,] attach(Intervall) # Standart deviation sdx -sd(x) sdy -sd(y) sdz -sd(z) # Add Behavior gene - as.character(Intervall[1,5]) # Construct a table tab -c(sdx, sdy, sdz, gene) write(tab, file=paste(VariableTable.txt, sep=), ncolumns=4,sep=,, append=TRUE) detach(Intervall) } # end of for loop The result looks like this and is fine: 1,1,1,grom 1.3,1.3,1.3,grom 1,1,1,vir My problem is, that I used the part column only to run the loop, but I actually want to use the time column to run the loop. But when I replace Intervall - AB[AB$part==i,] with Intervall - AB[AB$time==i,] then the resulting table only contains NA. I also tried to use Intervall - AB[x==i,] x - as.factor(AB$part) -- which works fine as well x - as.factor(AB$time) -- which returns only NA x - unique(AB$time) --- which returns only NA x - levels(unique(AB$time) -- which returns only NA x - seq(unique(AB$time) --- which returns the standard deviation of the entire column (not the single parts) What do I do wrong? And how can i fix it? Thank you so much in advance. Kind regards, Anna [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using a variable for a column name in a formula
Hi, I am getting this: #Using an example dataset: set.seed(24) X - data.frame(weight=sample(100:250,20,replace=TRUE),height=sample(140:190,20,replace=TRUE)) nnn - height res - lm(as.formula(paste(nnn, ~.)),data=X) res2 - lm(get(nnn) ~ . ,data=X) coef(res) (Intercept) weight 169.24873241 -0.03881928 coef(res2) (Intercept) weight height -7.890309e-14 1.518345e-17 1.00e+00 A.K. On Sunday, October 13, 2013 6:06 PM, p_connolly p_conno...@slingshot.co.nz wrote: On 2013-10-14 10:04, David Epstein wrote: lm(height ~ ., data=X) works fine. However nnn - height ; lm(nnn ~ . ,data=X) fails How do I write such a formula, which depends on the value of a string variable like nnn above? as.formula() with paste() could work, but from where you are now, try lm(get(nnn) ~ . ,data=X) HTH A typical application might be a program that takes a data frame containing only numerical data, and figures out which of the columns can be best predicted from all the other columns. Thanks David __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Looping over names of multiple data frames in an R for() loop XXXX
You might want to try: assign(d[1], read.csv(yourfile.csv)) ... write.csv(d1, yourfile.csv, append = FALSE) Regards Mikkel On Friday, October 11, 2013 2:53 PM, Dan Abner dan.abne...@gmail.com wrote: Hi everybody, I thought I was using the get() fn correctly here to loop over multiple data frame names in an R for() loop. Can someone advise? miss-c(#NULL!,999) d-c(d1,d2,d3,d4) for(i in 1:4){ + + miss1-ifelse(i=2,miss[1],miss[2]) + miss1 + + get(d[i])-read.csv(paste(C:\\DATA\\Data\\Original\\,dsn[i],sep=), + na.strings=c(miss1,9)) + + head(get(d[i])) + + write.csv(get(d[i]),paste(C:\\DATA\\Data\\,dsn[i],sep=), + na=.) + + } Error in get(d[i]) - read.csv(paste(C:\\DATA\\Data\\Original\\, dsn[i], : could not find function get- Thanks! Dan [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] RODBC on Mac
iODBC appears no longer to come standard with OSX, so I installed unixodbc and set it up following instructions here: http://www.boriel.com/en/2013/01/16/postgresql-odbc-connection-from-mac-os-x/ I connected to my remote database with isql -v mydsn. No problem. Then I tried from R: library(RODBC) pg - odbcConnect(mydsn) # waited for a couple of minutes before pressing Ctrl-C ^C There were 50 or more warnings (use warnings() to see the first 50) warnings()[1:2] Warning messages: 1: In odbcDriverConnect(DSN=mydsn) : [RODBC] ERROR: state IM002, code 1606406032, message [iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded 2: In odbcDriverConnect(DSN=mydsn) : [RODBC] ERROR: state IM002, code 1606406032, message [iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded It looks like RODBC might only work with iODBC on the Mac. Is that the case? I haven't been able to configure iODBC correctly, and therefore haven't been able to test whether that would work with RODBC. Any chance that I can get RODBC to work with unixodbc? Any other information that would be useful in resolving it? sessionInfo() R version 3.0.2 (2013-09-25) Platform: x86_64-apple-darwin10.8.0 (64-bit) locale: [1] C/UTF-8/C/C/C/C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] RODBC_1.3-8 Regards Mikkel PS. Apologies for repeating this message. I previously sent it with HTML formatting. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loop over factor returns NA
You'll need to tell us what class you time variable is in, e.g. the output of str(AB), but the following might work: for (i in unique(as.character(AB$time)) { Intervall - AB[as.character(AB$time) ==i, ] ... } Depending on the format, as.numeric( ) might work too. Regards Mikkel On Saturday, October 12, 2013 12:16 PM, anna berg anna.berg1...@hotmail.com wrote: Dear R users, I am pretty new to programming in R. So I guess there is some obvious mistake I am making. I hope you can help me. I have a data frame that looks like this: AB time x y z gene part 1 03:27:58 1 2 3 grom 1 2 03:27:58 2 3 4 grom 1 3 03:27:58 3 4 5 grom 1 4 04:44:23 12 13 14 grom 2 5 04:44:23 13 14 15 grom 2 6 04:44:23 14 15 16 grom 2 7 04:44:23 15 16 17 grom 2 8 06:23:45 101 102 103 vir 3 9 06:23:45 102 103 104 vir 3 10 06:23:45 103 104 105 vir 3 Now I want to apply a loop (here a simplified version; I know that I could do this easily with tapply, but for the other things that I want to do with the loop (e.g. weighted mean of time series after fast fourier transformation) I would rather like to use a loop). Note that time and part are actually the same, just one is a factor and the the other is a number. Here is the loop that works fine and returns the result as I want (the important part here is: Intervall - AB[AB$part==i,]): for(i in 1:length(unique(AB$time))) { Intervall - AB[AB$part==i,] attach(Intervall) # Standart deviation sdx -sd(x) sdy -sd(y) sdz -sd(z) # Add Behavior gene - as.character(Intervall[1,5]) # Construct a table tab -c(sdx, sdy, sdz, gene) write(tab, file=paste(VariableTable.txt, sep=), ncolumns=4,sep=,, append=TRUE) detach(Intervall) } # end of for loop The result looks like this and is fine: 1,1,1,grom 1.3,1.3,1.3,grom 1,1,1,vir My problem is, that I used the part column only to run the loop, but I actually want to use the time column to run the loop. But when I replace Intervall - AB[AB$part==i,] with Intervall - AB[AB$time==i,] then the resulting table only contains NA. I also tried to use Intervall - AB[x==i,] x - as.factor(AB$part) -- which works fine as well x - as.factor(AB$time) -- which returns only NA x - unique(AB$time) --- which returns only NA x - levels(unique(AB$time) -- which returns only NA x - seq(unique(AB$time) --- which returns the standard deviation of the entire column (not the single parts) What do I do wrong? And how can i fix it? Thank you so much in advance. Kind regards, Anna [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] ENMCA in EnQuireR problems!
Hello, I am a post-doc of the Federal University of Santa Catarina State (UFSC). Last year, used EnQuireR for hirarchical cluster analisis and end up very well. I formated my computer couple months ago and installed R again as version x64 3.0.2. have new data which ENMCA function of EnQuireR package is not running. R seems to be fine as it runs funcions of other packages. Even MCA fuction of EnQuireR is working well. This makes me understand that R is reading my data. In EnQuireR, after selecting the clusters, it run up to the two graphics and then stop in Device 3 with some error messages . Even the file exemple tea the ENMCA fuction is not running. What I did was: b-read.table(AbdonMCA_20131004.csv,header=T,row.names=1,sep=;,dec=,,na.string=nan) There is no problem to open the file. It runs frequency distribution by summary and other statistics. What I did was: b-read.table(AbdonMCA_20131004.csv,header=T,row.names=1,sep=;,dec=,,na.string=nan) It opens with no problem. Run frequency distribution by summary and other statistics. However, when it do the cluster analysis, it stops as soon as it gets Device 3 with the following error msg: b.res-ENMCA(b[,1:5]) Erro em if (del == 0 to == 0) return(to) : absent value where TRUE/FALSE is need Além disso: There were 50 or more warnings (use warnings() to see the first 50) OR SOMETHINGS: Erro em seq.default(-ylimit, ylimit, 0.01 * ylimit) : 'from' cannot be NA, NaN or infinite Além disso: There were 50 or more warnings (use warnings() to see the first 50) For your information, data has some missing values. I have the R x64 3.0.2. I use Windows 64bits. I do appreciate any suggestion. Regards Cibele __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Splitting times into groups based on a range of times
Hi Ben, It looks like the condition is not met in majority of the split elements. So, when you create a dataframe with the a column with 0 element and another column with an element, it shows the Error message. data.frame(dt2=NULL,group=1) #Error in data.frame(dt2 = NULL, group = 1) : # arguments imply differing number of rows: 0, 1 You can do this: lst1 - split(df.new,df.new$start.end.group) lst2 - lapply(lst1,function(x){dt2=dt.new[dt.new=x[1,1] dt.new x[length(x),1]]}) lst3 - lst2[lapply(lst2,length)0] df1.new - do.call(rbind,lapply(lst1[names(lst1)%in% names(lst3)],function(x) {data.frame(dt2=dt.new[dt.new= x[1,1] dt.new x[length(x),1]],group=x[1,2])})) #You could also do this from `lst3` and create groups as the names of the list elements as both are the same. head(df1.new) # dt2 group #61.1 2012-08-02 19:16:14 61 #61.2 2012-08-02 19:18:14 61 #61.3 2012-08-02 19:20:14 61 #61.4 2012-08-02 19:22:14 61 #61.5 2012-08-02 19:24:14 61 #61.6 2012-08-02 19:26:14 61 tail(df1.new[df1.new$group==61,],2) # dt2 group #61.366 2012-08-03 07:26:14 61 #61.367 2012-08-03 07:28:14 61 lst1[[61]] # dt2.new start.end.group #61 2012-08-02 19:15:00 61 #200 2012-08-03 07:30:00 61 A.K. On Sunday, October 13, 2013 3:55 PM, Benjamin Gillespie gy...@leeds.ac.uk wrote: Hi Arun, This is great - it works perfectly for the data I provided you. However, I've spent almost all today trying to apply it to my real world dataset... and for some reason I keep getting the error: Error in data.frame(dt2 = dt.new[dt.new = x[1, 1] dt.new x[length(x), : arguments imply differing number of rows: 0, 1 when trying to build df1. It's quite odd and I can't figure out why!! I have attached my script file and two data files. logger2.csv is used to create 'df' and discharge.csv is used to define the 'floods' (it includes river discharge data) which are then assigned ID's. As before, I want to then assign these flood id's to the relevant times in 'df'. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R plotting
Hi This seems to work: spdata$color - ifelse(spdata$change 0, red, green) plot(spdata$date, log(spdata$close), col = spdata$color) Regards Mikkel On Friday, October 11, 2013 5:14 PM, Mubar simon.keu...@student.unisg.ch wrote: Hi I have a question regarding plots in R. I have data from the SP 500 in the format: date close change 1980-01-07 109.92 3.4 I plotted the data with plot(spdata$date, log(spdata$close), type=p) Now I want to ad the colors green and red to the data frame. if the change is positive it should be green, if negative, red. Also the colors should be in the plot. I tried to do this with the ifelse function, but seem to be stuck. Can anyone help me with this? Thanks a lot! -- View this message in context: http://r.789695.n4.nabble.com/R-plotting-tp4678056.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R help
Dear, I want to use for loop and if..else condition together for finding such value from a two column in a spreadsheet. Thanks Regards Shameem Akhtar [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.