Re: [R] how to assemble data frame of unknown number of columns in loop

2011-04-24 Thread Rolf Turner
On 24/04/11 16:44, Nevil Amos wrote: How do I assemble ad data fame, consisting of columns form other data frames identified in a loop? cbind is not working as the initial data fame has 0 columns and rows. > ModList<-dir("./MODEL_DISTS/") > ModList<-ModList[grep(pattern="3COLUMNS",ModList)]

Re: [R] How to erase (replace) certain elements in the data.frame?

2011-04-24 Thread Joshua Wiley
Hi Sergey, This is not an answer to your exact question, but can you use a matrix? If you can use a matrix instead of a data frame, you should get a considerable performance boost. Even for very large matrices (at least on my system), it is fast enough I find it hard to believe it is a bottle ne

Re: [R] How to erase (replace) certain elements in the data.frame?

2011-04-24 Thread Thomas Levine
This should do the same thing random.del <- function (x, n.keeprows, del.percent){   del<-function(col){     col[sample.int(length(col),length(col)*del.percent/100)]<-NA     col   }   change<-n.keeprows:nrow(x)   x[change,]<-lapply(x[change,],del)   x } This is faster because it's vectorized. [1

Re: [R] Matching a vector with a matrix row

2011-04-24 Thread Petr Savicky
On Sat, Apr 23, 2011 at 08:56:33AM +0800, Luis Felipe Parra wrote: > Hello Niels, I am trying to find the rows in Matrix which contain all of the > elements in LHS. This sounds like you want an equivalent of all(LHS %in% x) However, in your original post, you used all(x %in% LHS) What is c

[R] set.seed( ) function

2011-04-24 Thread Penny Bilton
Thank you for the help so far. Also, I don't quite understand what the set.seed function does. Does it choose a starting point for the random number generation? Thanks, Penny. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinf

Re: [R] set.seed( ) function

2011-04-24 Thread Petr Savicky
On Sun, Apr 24, 2011 at 10:10:45PM +1200, Penny Bilton wrote: > Thank you for the help so far. Also, I don't quite understand what the > set.seed function does. Does it choose a starting point for the random > number generation? Yes. The generator produces a periodic sequence, which may be unde

Re: [R] help with "\" in strings

2011-04-24 Thread Uwe Ligges
On 24.04.2011 08:02, Joshua Wiley wrote: Hi Rob, On Sat, Apr 23, 2011 at 7:19 PM, viostorm wrote: I would like to create a "\%" that can be written to a file as I am writing a procedure to output to latex. I can't create a "\%" and it is driving me crazy. Try the fixed = TRUE argument to

Re: [R] random typing over text

2011-04-24 Thread Peter Ehlers
On 2011-04-23 16:11, Duncan Murdoch wrote: On 11-04-23 6:13 PM, derek wrote: Thank you very much. It was the Insert key. It was very annoying. Actually is this owerwrite function of any use? It's excellent when you want to overwrite text. Duncan Murdoch This made me smile. Although not R-sp

Re: [R] EM vs Bayesian

2011-04-24 Thread Jim Silverton
Hello, Is there any literature there that says that the EM is better/worse than a Baysian model when it comes to differentiating univariate mixture of normal distributions? -- Thanks, Jim. [[alternative HTML version deleted]] __ R-help@r-proje

[R] should I use setRefClass() ?

2011-04-24 Thread Ben Nachtrieb
Hello, I am somewhat new to R programming and a novice C++ programmer. I'd like to know if I should use setRefClass() to manage objects, functions, and data in a very large program I am attempting to code. See: http://stat.ethz.ch/R-manual/R-devel/library/methods/html/refClass.html I like the re

Re: [R] filling array with functions

2011-04-24 Thread derek
Thats not exactly what I hoped for. But for now it has to suffice. More transparent syntax would be nicer. Exactly what I would like to do is: for (i in 1:9){ f[i]<-function(x){ a*x+b) } curve(f[i], 0, 8) sol[i]<-uniroot(f[i],c(0, 8))$root points(sol[i],0,pch=16,cex=1,col="red") } Perhaps is

Re: [R] How to erase (replace) certain elements in the data.frame?

2011-04-24 Thread Joshua Wiley
On Sat, Apr 23, 2011 at 11:35 PM, Thomas Levine wrote: > This should do the same thing Did you actually test it? I get very different things. > > random.del <- function (x, n.keeprows, del.percent){ >   del<-function(col){ >     col[sample.int(length(col),length(col)*del.percent/100)]<-NA >    

Re: [R] How to erase (replace) certain elements in the data.frame?

2011-04-24 Thread sneaffer
Thanks a lot, guys. Thomas, your method is great, precisely the thing I've been looking forward to. Oh dear, how I love R for those list comprehension tricks! -- View this message in context: http://r.789695.n4.nabble.com/How-to-erase-replace-certain-elements-in-the-data-frame-tp3470883p3471380.h

Re: [R] help with "\" in strings

2011-04-24 Thread viostorm
Josh, Thank you so much!!! Works perfectly! -Rob Robert Schutt III, MD, MCS Resident - Department of Internal Medicine University of Virginia, Charlottesville, Virginia -- View this message in context: http://r.789695.n4.nabble.com/help-with-in-strings-tp3470

Re: [R] simple loop questions

2011-04-24 Thread David Winsemius
On Apr 23, 2011, at 9:34 AM, David Winsemius wrote: On Apr 23, 2011, at 6:31 AM, wrote: Hi all, I am trying to write a loop to return the matched index for a column of values. Here is an simple example of this, A B 0 5 1 2 2 2 3 4 4 1 5 4 6 2 In this case, A is an inde

Re: [R] Using Java methods in R

2011-04-24 Thread hill0093
Thanks Icn, for suggesting .jaddClassPath I finally had time to play around and discover what you meant. So I am one step farther than the report in the second post above: I have the RGui with R Console on the screen. On the top pullDowns, Packages > Install Packages > USA(IA)> rJava > library(rJa

[R] How to offer a patch to a help page?

2011-04-24 Thread Tal Galili
Hello all, I wish to offer a patch to a help page (specifically ?update.packages). Might you please direct me as to where to find the file, and how might it be best to edit it? (on windows) (My apologies for the n00b question...) Best, Tal Contact Details:--

Re: [R] How to offer a patch to a help page?

2011-04-24 Thread Duncan Murdoch
On 11-04-24 12:51 PM, Tal Galili wrote: Hello all, I wish to offer a patch to a help page (specifically ?update.packages). Might you please direct me as to where to find the file, and how might it be best to edit it? (on windows) (My apologies for the n00b question...) In the R sources, the h

Re: [R] How to erase (replace) certain elements in the data.frame?

2011-04-24 Thread Thomas Levine
As Joshua said, mine was indeed different from yours. And it didn't work on non-numeric data. But this one seems to work right: random.del_vec <- function (x, n.keeprows, del.percent){ del<-function(notkeep){ k<-floor(length(notkeep)*del.percent/100) notkeep[sample.int(length(notkeep),k)

Re: [R] Matching a vector with a matrix row

2011-04-24 Thread Ravi Varadhan
I gave a solution previously with integer elements. It also works well for real numbers. rowMatch <- function(A,B) { # Rows in A that match the rows in B # The row indexes correspond to A f <- function(...) paste(..., sep=":") if(!is.matrix(B)) B <- matrix(B, 1, length(B)) a <- do.cal

Re: [R] Using Java methods in R

2011-04-24 Thread hill0093
So I am one step farther than last time, so I am happy: I have the RGui with R Console on the screen. On the top pullDowns, Packages > Install Packages > USA(IA)> rJava > library(rJava) > .jinit() > .jaddClassPath("C:/ad/j") > print(.jclassPath()) [1] "C:\\Users\\ENVY17\\Documents\\R\\win-library\

[R] If Then Trouble

2011-04-24 Thread Sparks, John James
Dear R Helpers, I have another one of those problems involving a very simple step, but due to my inexperience I can't find a way to solve it. I had a look at a number of on-line references, but they don't speak to this problem. I have a variable with 20 values > table (testY2$redgroups) 1

Re: [R] If Then Trouble

2011-04-24 Thread jim holtman
?ifelsethis is vectorized 'if' only handles single values testY2$redgroups <- ifelse(testY2$redgroups > 17, 17, testY2$redgroups) On Sun, Apr 24, 2011 at 4:10 PM, Sparks, John James wrote: > Dear R Helpers, > > I have another one of those problems involving a very simple step, but due > to

Re: [R] If Then Trouble

2011-04-24 Thread Joshua Wiley
Hi John, On Sun, Apr 24, 2011 at 1:10 PM, Sparks, John James wrote: > Dear R Helpers, > > I have another one of those problems involving a very simple step, but due > to my inexperience I can't find a way to solve it.  I had a look at a > number of on-line references, but they don't speak to this

Re: [R] If Then Trouble

2011-04-24 Thread Uwe Ligges
On 24.04.2011 22:10, Sparks, John James wrote: Dear R Helpers, I have another one of those problems involving a very simple step, but due to my inexperience I can't find a way to solve it. I had a look at a number of on-line references, but they don't speak to this problem. I have a variable

[R] merge with origin information in new variable names

2011-04-24 Thread Eric Fail
Dear R-list, Here is my simple question, I have n data frames that I would like to merge, but I can't figure out how to add information about the origin of the variable(s). Here is my problem, DF.wave.1 <- data.frame(id=1:10,var.A=sample(letters[1:4],10,TRUE)) DF.wave.2 <- data.frame(id=1:10,va

Re: [R] filling array with functions

2011-04-24 Thread Richard M. Heiberger
Derek, You need a list. f1 <- function(x) sin(x) f2 <- function(x) cos(x) f.list <- list(f1, f2) f.list[[1]](pi) f.list[[2]](pi) ## Note the double '[[' indexing. ## You can dimension a list to allow multiple-index indexing. dim(f.list) <- c(2,1) f.list[[1,1]](pi) Rich On Sun, Apr 24, 2011 a

Re: [R] Multi-dimensional non-linear fitting - advice on best method?

2011-04-24 Thread David Winsemius
On Apr 23, 2011, at 8:38 PM, Julian Gilbey wrote: Hello! I have a set of data of the form (x, y1, y2) where x is the independent variable and (y1, y2) is the response pair. The model is some messy non-linear function: (y1, y2) = f(x; param1, param2, ..., paramk) + (y1error, y2error) where

Re: [R] Multi-dimensional non-linear fitting - advice on best method?

2011-04-24 Thread peter dalgaard
On Apr 24, 2011, at 02:38 , Julian Gilbey wrote: > Hello! > > I have a set of data of the form (x, y1, y2) where x is the > independent variable and (y1, y2) is the response pair. The model is > some messy non-linear function: > > (y1, y2) = f(x; param1, param2, ..., paramk) + (y1error, y2err

[R] Random Normal Variable Correlated to an Existing Binomial Variable

2011-04-24 Thread Shane Phillips
Hi, R-Helpers! I have a dataframe that contains a binomial variable. I need to add another random variable drawn from a normal distribution with a specific mean and standard deviation. This variable also needs to be correlated with the existing binomial variable with a specific correlation (s

Re: [R] Multi-dimensional non-linear fitting - advice on best method?

2011-04-24 Thread Ravi Varadhan
Julian, You have not specified your problem fully. What is the nature of f? Is f a scalar function or is it a vector function (2-dim)? Here are some examples showing different possibilities: (1) y1 = f + e1 = a + b*exp(-c*x) + e1; y2 = f + e2 = a + b*exp(-c*x) + e2; (e1, e2) ~ bivariate norm

Re: [R] Using Java methods in R

2011-04-24 Thread hill0093
I added this R code to the bottom of the previous code and it doesn't work > ar34Ret <- .jcall(qsLin,returnSig="[[D","arReturnTEST") > print(ar34Ret,digits=20) [[1]] [1] "Java-Array-Object[D:[D@8813f2" [[2]] [1] "Java-Array-Object[D:[D@1d58aae" [[3]] [1] "Java-Array-Object[D:[D@83cc67" > for(i

Re: [R] merge with origin information in new variable names

2011-04-24 Thread Jeff Newmiller
Merge only lets you combine two tables at a time, but it does have a "suffix" argument that is intended to address your concern, but only for variable names that would conflict. In your example, the id variables are all sequenced exactly the same, so you could actually use cbind rather than mer

Re: [R] random typing over text

2011-04-24 Thread Jim Lemon
On 04/24/2011 08:13 AM, derek wrote: Thank you very much. It was the Insert key. It was very annoying. Actually is this owerwrite function of any use? Hi derek, As Duncan mentioned, it is very useful when one wishes to type over existing text. However, this is a fairly uncommon wish in the typ

[R] return code 10 in the R documentation

2011-04-24 Thread swarna14
Hi Everyone, I have group of R jobs that should be submitted to the condor when I submit the jobs to the condor, they don't run and when I checked the Sched Log files the jobs are exiting with status code 10. Previously, the jobs ran well on condor but now when I submit the jobs on condor they are

Re: [R] Multi-dimensional non-linear fitting - advice on best method?

2011-04-24 Thread ancienthart
If y1 and y2 are only dependent on x, can't you model them separately? Joal Heagney __ 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

Re: [R] return code 10 in the R documentation

2011-04-24 Thread Jim Lemon
On 04/25/2011 12:26 PM, swarna14 wrote: Hi Everyone, I have group of R jobs that should be submitted to the condor when I submit the jobs to the condor, they don't run and when I checked the Sched Log files the jobs are exiting with status code 10. Previously, the jobs ran well on condor but now

[R] average among one factor in a nested dataframe

2011-04-24 Thread Junqian Gordon Xu
I have two nested data frames: a<-rnorm(6) b<-rnorm(9) f1<-c("x1","x2","x3")) f2<-c("y1","y2") id<-c(1:6) a_df<-data.frame(cbind(id,f1,"y1",a)) id<-c(1:9) b_df<-data.frame(cbind(id,f1,"y2",b)) I want to preserve id and f1, but want to collapse f2 and take the corresponding mean values of a and b.