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)]
> ALL_MODELS<-data.frame()
> for (i in ModList){
+ X<-read.table(file=paste("./MODEL_DISTS/",i,sep=""))
+ BASE=sub("3COLUMNS","" , i, fixed = TRUE)
+ names(X)<-c("FromSiteID","ToSiteID","CS_RESISTANCE")
+ ALL_MODELS<-cbind(ALL_MODELS,X[3])
+ }
Error in data.frame(..., check.names = FALSE) :
  arguments imply differing number of rows: 0, 2080

Start with ALL_MODELS <- NULL r.t. ALL_MODELS <- data.frame().

cheers,

Rolf Turner

__
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 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 neck in the overall imputation process.  For example,
for a 1000 by 100 object
as a data frame:
> system.time(r0 <- random.del(mat, 100, 50))
   user  system elapsed
   1.090.021.12
and as a matrix:
> system.time(r0 <- random.del(mat, 100, 50))
   user  system elapsed
   0.020.000.01

Beyond that, for very large objects, this revision gives a slight
(i.e., around 5 seconds for 1 million by 100 column object on my
system) performance increase, which is small for matrices and
completely dwarfed by other bottlenecks for data frames, at the cost
of readability/flexibility:

rdel <- function (x, n.keeprows, del.percent){
  n.items <- ncol(x)
  k <- as.integer(n.items * del.percent / 100)
  cols <- 1:n.items
  lcols <- length(cols)
  for (i in (n.keeprows+1):nrow(x)){
j <- cols[.Internal(sample(lcols, k, FALSE, NULL))]
x[i,j] <- NA
  }
  return(x)
}

If you must use a data frame, you can gain some performance increase
(for a 1 by 100 data frame, it takes about 30 seconds on my system
versus 40 for your original function) by using:

random.del2 <- function (x, n.keeprows, del.percent){
  n.items <- ncol(x)
  k <- n.items*(del.percent/100)
  for (i in (n.keeprows+1):nrow(x)){
j <- sample(1:n.items, k)
`[<-.data.frame`(x, i, j, NA)
  }
  return(x)
}

which basically just saves R the trouble of figuring out which
assignment method to use.  Of course the problem is that your function
becomes extremely specialized.  If you pass anything to it but a data
frame, good things will not happen.

Cheers,

Josh

On Sat, Apr 23, 2011 at 5:37 PM, sneaffer  wrote:
> Hello R-world,
> Please, help me to get round my little mess
> I have a data.frame in which I'd rather like some values to be NA for the
> future imputation process.
>
> I've come up with the following piece of code:
>
> random.del <- function (x, n.keeprows, del.percent){
>  n.items <- ncol(x)
>  k <- n.items*(del.percent/100)
>  x.del <- x
>  for (i in (n.keeprows+1):nrow(x)){
>    j <- sample(1:n.items, k)
>    x.del[i,j] <- NA
>  }
>  return (x.del)
> }
>
> The problems is that random.del turns out to be slow on huge samples.
> Is there any other more effective/charming way to do the same?
>
> Thanks,
> Sergey
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/How-to-erase-replace-certain-elements-in-the-data-frame-tp3470883p3470883.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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.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.


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] "Mine"
   user  system elapsed
  0.004   0.000   0.002
[1] "Yours"
   user  system elapsed
  1.172   0.020   1.193

Tom

On Sat, Apr 23, 2011 at 8:37 PM, sneaffer  wrote:
>
> Hello R-world,
> Please, help me to get round my little mess
> I have a data.frame in which I'd rather like some values to be NA for the
> future imputation process.
>
> I've come up with the following piece of code:
>
> random.del <- function (x, n.keeprows, del.percent){
>  n.items <- ncol(x)
>  k <- n.items*(del.percent/100)
>  x.del <- x
>  for (i in (n.keeprows+1):nrow(x)){
>    j <- sample(1:n.items, k)
>    x.del[i,j] <- NA
>  }
>  return (x.del)
> }
>
> The problems is that random.del turns out to be slow on huge samples.
> Is there any other more effective/charming way to do the same?
>
> Thanks,
> Sergey
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/How-to-erase-replace-certain-elements-in-the-data-frame-tp3470883p3470883.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.


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

If the equality of x and LHS should be tested, then try

   setequal(x, LHS)

If the rows may contain repeated elements and the number of
repetitions should also match, then try

  identical(sort(x), sort(LHS))

with a precomputed sort(LHS) for efficiency.

If the number of the different character values in the whole
matrix is not too large, then efficiency of the comparison
may be improved, if the matrix is converted to a matrix
consisting of integer codes instead of the original character
values. See ?factor for the meaning of "integer codes".
After this conversion, the comparison can be done by comparing
integers instead of character values, which is faster.

Hope this helps.

Petr Savicky.

__
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] 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/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] 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 understood
as a long cycle. The seed specifies a starting point in this cycle. For
the default generator in R, the period is 2^19937-1, which is a Mersenne
prime. The period is long enough so that it cannot be exhausted. The 
function set.seed() allows to choose between approximately 2^32 different
starting points.

Petr Savicky.

__
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] 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 gsub.  This works for me:

x = "This is a test % string"
writeLines(gsub ("%", "\\%", x, fixed = TRUE), "c:/biostats/test.txt")


or just use "%"
one escape for R and one for the regexp each.

Uwe Ligges



Cheers,

Josh



--

x = "This is a test % string"
gsub ("%", "\\%", x)
fileConn<-file("c:/biostats/test.txt")
writeLines(x, fileConn)
close(fileConn)

--

Any suggestions?

Thanks in advance.

--
View this message in context: 
http://r.789695.n4.nabble.com/help-with-in-strings-tp3470964p3470964.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.


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-specific, can such a quote be 'fortuned'?

Peter Ehlers

__
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] 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-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] 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 referential class structure that C++ provides and R seems to
provides via setRefClass(). Mainly what I like is that I can code custom
member functions that 'do stuff' inside a class.

I understand that setRefClass() kind of gets away from the way R was
intended to be used. It is this 'understanding' that makes me worry about
using something setRefClass(). The program that I am attempting to build is
very big, complex (for me), and it needs to be efficient (from a code
readability standpoint and from a speed standpoint). I will be using a lot
of the built-in R stats-centric functions. Are there any pitfalls I should
be aware of? Any insight or suggestions? I was thinking the setRefClass()
function would provide what I like in C++, but allow me to do everything in
R (rather than having C++ and R interface with each other).

Thanks for any help!

Ben

[[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] 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 item for a wish list?

--
View this message in context: 
http://r.789695.n4.nabble.com/filling-array-with-functions-tp3468313p3471463.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.


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
>     col
>   }
>   change<-n.keeprows:nrow(x)
>   x[change,]<-lapply(x[change,],del)

but a data frame is a list of vectors column wise, while Sergey's
function went row by row.  However, using sample.int() is a much
better idea than what I did with sample().

>   x
> }
>
> This is faster because it's vectorized.

but in such a way that you cannot guarantee the same number of cells
are missing from each row.  Try:

rowSums(is.na("Mine"))

>
> [1] "Mine"
>   user  system elapsed
>  0.004   0.000   0.002
> [1] "Yours"
>   user  system elapsed
>  1.172   0.020   1.193
>
> Tom
>
> On Sat, Apr 23, 2011 at 8:37 PM, sneaffer  wrote:
>>
>> Hello R-world,
>> Please, help me to get round my little mess
>> I have a data.frame in which I'd rather like some values to be NA for the
>> future imputation process.
>>
>> I've come up with the following piece of code:
>>
>> random.del <- function (x, n.keeprows, del.percent){
>>  n.items <- ncol(x)
>>  k <- n.items*(del.percent/100)
>>  x.del <- x
>>  for (i in (n.keeprows+1):nrow(x)){
>>    j <- sample(1:n.items, k)
>>    x.del[i,j] <- NA
>>  }
>>  return (x.del)
>> }
>>
>> The problems is that random.del turns out to be slow on huge samples.
>> Is there any other more effective/charming way to do the same?
>>
>> Thanks,
>> Sergey
>>
>> --
>> View this message in context: 
>> http://r.789695.n4.nabble.com/How-to-erase-replace-certain-elements-in-the-data-frame-tp3470883p3470883.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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.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.


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


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


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 index column for B. Now I have this new  
column C with just two values of 2 and 4. I want to match column C  
with column B, and return the matched indexes. So what I desire is  
to return:


[1] 1 2 6
[2] 3 5

Since value 2 corresponds to indexes 1,2,6, and 4 corresponds to  
indexes 3,5.


Assuming this to be in a data.frame named dat:

> dat$A[which(dat$B==2) ]
[1] 1 2 6


I've been reminded that in many instances one gets comparable results  
with dat$A[ dat$B==2 ] (logical indexing).


The reason I choose to use which() is that it returns a numeric vector  
and leaves out any NA's that result from dat$B==2. the "[" function  
returns all logical NA rows. It may be important to return such NA's  
to alert the analyst to their presence. (This does result in extensive/ 
useless/unexpected screen output when large datasets with even a small  
faction of NA's are being manipulated.)


--
David


> dat$A[which(dat$B==4) ]
[1] 3 5





Results of varying lengths generally need to be returned in list form:

> sapply(c(2,4), function(x) dat$A[which(dat$B==x) ] )
[[1]]
[1] 1 2 6

[[2]]
[1] 3 5





David Winsemius, MD
West Hartford, CT

__
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 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(rJava)
> .jinit()
> ## > ?rJava::.jaddClassPath
> .jaddClassPath("C:/ad/j")  ##or > .jaddClassPath("C:\\ad\\j")
> print(.jclassPath())
[1] "C:\\Users\\ENVY17\\Documents\\R\\win-library\\2.12\\rJava\\java"
[2] "C:\\ad\\j"  
> qsLin <- .jnew("CalqsLin")
> dblTim <-
> .jcall(qsLin,returnSig="D","linTimOfCalqsStgIsLev","20110405235959","-4")
Error in .jcall(qsLin, returnSig = "D", "linTimOfCalqsStgIsLev",
"20110405235959",  : 
  method linTimOfCalqsStgIsLev with signature
(Ljava/lang/String;Ljava/lang/String;)D not found
> 

What's wrong?
Just to show my intentions, 
I had next wanted to call this java function method:
linTimOfCalqsStgIsLev("20110405235959",-4) 


--
View this message in context: 
http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3471705.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] 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:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--

[[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 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 help pages are stored in 
src/library//man, or occasionally in a platform-specific 
subdirectory of that.  Since update.packages is in the utils package, 
that would be src/library/utils/man.  The name of the page is 
"update.packages", so a first guess would be to look in a file called 
"update.packages.Rd", and that is indeed the right file.


Generally if you are putting together a patch, you should get agreement 
on the R-devel list that the change is worth making before putting a lot 
of effort into it, because not all patches are accepted.  If it is a 
very minor thing (e.g. correcting a typo), the simplest thing is to post 
the suggested correction to the R-devel list.


Duncan Murdoch

__
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 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)]<-NA
notkeep
  }
  change<-(n.keeprows+1):nrow(x)
   x[change,]<-t(apply(x[change,],1,del))
  x
}

On the other hand, maybe you really didn't want the stratification by row.

Tom

On Sun, Apr 24, 2011 at 8:31 AM, sneaffer  wrote:
> 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.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.


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.call("f", as.data.frame(A))
b <- do.call("f", as.data.frame(B))
match(b, a)
}

A <- matrix(rnorm(10), 5000, 20)
sel <- sample(1:nrow(A), size=100, replace=TRUE)
B <- A[sel,]

system.time(rows <- rowMatch(A, B ))
all.equal(sel, rows)

sel <- sample(1:nrow(A), size=1)
b <- c(A[sel,])
system.time(row <- rowMatch(A, b))
all.equal(sel, row)

I am curious to see if there are better/faster ways to do this.

Ravi.

From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
Petr Savicky [savi...@praha1.ff.cuni.cz]
Sent: Sunday, April 24, 2011 5:13 AM
To: r-help@r-project.org
Subject: Re: [R] Matching a vector with a matrix row

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

If the equality of x and LHS should be tested, then try

   setequal(x, LHS)

If the rows may contain repeated elements and the number of
repetitions should also match, then try

  identical(sort(x), sort(LHS))

with a precomputed sort(LHS) for efficiency.

If the number of the different character values in the whole
matrix is not too large, then efficiency of the comparison
may be improved, if the matrix is converted to a matrix
consisting of integer codes instead of the original character
values. See ?factor for the meaning of "integer codes".
After this conversion, the comparison can be done by comparing
integers instead of character values, which is faster.

Hope this helps.

Petr Savicky.

__
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 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\\2.12\\rJava\\java"
[2] "C:\\ad\\j"  
> qsLin <- .jnew("CalqsLin")
> calStg <- "20110424235959"
> print(calStg)
[1] "20110424235959"
> dblTim <-
> .jcall(qsLin,returnSig="D","linTimOfCalqsStgIsLev",calStg,as.integer(-4))
> print(dblTim,digits=20)
[1] 63470908799
> calStg <-
> .jcall(qsLin,returnSig="S","calqsStgOfLinTimIsLev",dblTim,as.integer(-4))
> print(calStg)
[1] "20110424235959"
> dblTim <-
> .jcall(qsLin,returnSig="D","linTimOfCalqsStgIsLev",calStg,as.integer(-4))
> print(dblTim,digits=20)
[1] 63470908799
> 


--
View this message in context: 
http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3471943.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] 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 2 3 4 5 6 7 8 9101112   
1314151617181920
   69   734  6079 18578 13693  6412  3548  1646   659   323   12988   
904057333617 613

Values 18,19 and 20 have small counts.  So, I want to set the value of
redgroups for these rows to 17 in order to combine groups.  I would think
that it would be as easy as

if(testY2$redgroups>17) testY2$redgroups<-17

following the syntax that I have seen in the manuals.  However, I get the
error message

Warning message:
In if (testY2$redgroups > 17) testY2$redgroups <- 17 :
  the condition has length > 1 and only the first element will be used

Can someone please tell me the correct syntax for this?  I would really
appreciate it.

Appreciatively yours,
--John J. Sparks, Ph.D.

__
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] 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 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     2     3     4     5     6     7     8     9    10    11    12
> 13    14    15    16    17    18    19    20
>   69   734  6079 18578 13693  6412  3548  1646   659   323   129    88
> 90    40    57    33    36    17     6    13
>
> Values 18,19 and 20 have small counts.  So, I want to set the value of
> redgroups for these rows to 17 in order to combine groups.  I would think
> that it would be as easy as
>
> if(testY2$redgroups>17) testY2$redgroups<-17
>
> following the syntax that I have seen in the manuals.  However, I get the
> error message
>
> Warning message:
> In if (testY2$redgroups > 17) testY2$redgroups <- 17 :
>  the condition has length > 1 and only the first element will be used
>
> Can someone please tell me the correct syntax for this?  I would really
> appreciate it.
>
> Appreciatively yours,
> --John J. Sparks, Ph.D.
>
> __
> 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.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

__
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] 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 problem.
>
> I have a variable with 20 values
>
>> table (testY2$redgroups)
>
>    1     2     3     4     5     6     7     8     9    10    11    12
> 13    14    15    16    17    18    19    20
>   69   734  6079 18578 13693  6412  3548  1646   659   323   129    88
> 90    40    57    33    36    17     6    13
>
> Values 18,19 and 20 have small counts.  So, I want to set the value of
> redgroups for these rows to 17 in order to combine groups.  I would think
> that it would be as easy as
>
> if(testY2$redgroups>17) testY2$redgroups<-17

"if" is not vectorized, it is designed for using in things like logic
trees (e.g., if (na.rm) {remove-missing-values} else ).  You are
looking for ifelse (see ?ifelse for documentation).  Something like:

testY2$redgroups <- with(testY2, ifelse(redgroups > 17, 17, redgroups))

HTH,

Josh

>
> following the syntax that I have seen in the manuals.  However, I get the
> error message
>
> Warning message:
> In if (testY2$redgroups > 17) testY2$redgroups <- 17 :
>  the condition has length > 1 and only the first element will be used
>
> Can someone please tell me the correct syntax for this?  I would really
> appreciate it.
>
> Appreciatively yours,
> --John J. Sparks, Ph.D.
>
> __
> 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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.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.


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 with 20 values


table (testY2$redgroups)


 1 2 3 4 5 6 7 8 9101112
1314151617181920
69   734  6079 18578 13693  6412  3548  1646   659   323   12988
904057333617 613

Values 18,19 and 20 have small counts.  So, I want to set the value of
redgroups for these rows to 17 in order to combine groups.  I would think
that it would be as easy as

if(testY2$redgroups>17) testY2$redgroups<-17

following the syntax that I have seen in the manuals.  However, I get the
error message

Warning message:
In if (testY2$redgroups>  17) testY2$redgroups<- 17 :
   the condition has length>  1 and only the first element will be used

Can someone please tell me the correct syntax for this?  I would really
appreciate it.


See help("if") and find if(foo) is only designed for scalar values of 
foo. You actually want to use:


if(testY2$redgroups>17) testY2$redgroups<-17

testY2$redgroups[testY2$redgroups > 17] <- 17

or using some less efficient "if"-like statement:

testY2$redgroups <- ifelse(testY2$redgroups > 17, 17, testY2$redgroups)


Uwe Ligges






Appreciatively yours,
--John J. Sparks, Ph.D.

__
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] 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,var.M=sample(letters[5:8],10,TRUE))
DF.wave.3 <- data.frame(id=1:10,var.A=sample(letters[5:8],10,TRUE))

Now; I would like to merge the three dataframes into one, but append a
suffix to the individual variables names about thir origin.

DF.wave.all <- merge(DF.wave.1,DF.wave.2,DF.wave.3,by="id", [what to do here])

In other words, I would like it to loook like this.

DF.wave.all
   id var.A.wave.1 var.M.wave.2 var.A.wave.3
1   1chj
2   2cej
3   3cgk
4   4cej
5   5cgi
6   6dek
7   7chk
8   8bgj
9   9bfi
10 10dhi


Is there a command I can use directly in merge? 'suffixes' isn't
really handy here.

Thanks,
Eric

__
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] 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 at 9:37 AM, derek  wrote:

> 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 item for a wish list?
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/filling-array-with-functions-tp3468313p3471463.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.
>

[[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] 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 the parameters param1, ..., paramk are to be estimated, and I'll
assume the errors to be normal for sake of simplicity.

If there were only one response per input, I would use the nls()
function, but what can I do in this case?


I wonder it would be sensible or at least informative to consider  
solving for the "inverse case". i.e. solve for:


x = f(y1, y2)

--
David Winsemius, MD
West Hartford, CT

__
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] 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, y2error)
> 
> where the parameters param1, ..., paramk are to be estimated, and I'll
> assume the errors to be normal for sake of simplicity.
> 
> If there were only one response per input, I would use the nls()
> function, but what can I do in this case?


I believe the gnls function in the nlme package is your friend. It's a bit 
involved but the basic idea is to stack the two response variables and use a 
weights argument with a varIdent structure with variance depending on whether 
it is a y1 or a y2 observation. You can also specify a within-pair correlation.

> 
> Many thanks,
> 
>   Julian
> 
> __
> 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.

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.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] 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 (say .75).  Any ideas?

Thanks!

Shane
__
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] 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 normal

(2) y1 = f + e1 = a + b*exp(-c*x) + e1; y2 = f + e2 = a + b*exp(-c*x) + e2; 
(e1, e2) ~ independently normal

(3) y1 = f1 + e1 = a1 + b1*exp(-c1*x) + e1; y2 = f2 + e2 = a2 + b2*exp(-c2*x) + 
e2; (e1, e2) ~ bivariate normal

(4) y1 = f1 + e1 = a1 + b1*exp(-c1*x) + e1; y2 = f2 + e2 = a2 + b2*exp(-c2*x) + 
e2; (e1, e2) ~ independently normal

For scenario (2), you form a single `y' vector by concatenating all the y1 and 
y2 and then do a single application of nls.  For (4), you do 2 separate nls 
runs, one for y1 and another for y2.  

For (1) and (3) you can do a likelihood maximization.

You have more scenarios where f1 and f2 can have different functional forms.  
Which scenario is the one that you are considering?

Ravi.

From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
David Winsemius [dwinsem...@comcast.net]
Sent: Sunday, April 24, 2011 6:25 PM
To: Julian Gilbey
Cc: r-help@r-project.org
Subject: Re: [R] Multi-dimensional non-linear fitting - advice on best  method?

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 the parameters param1, ..., paramk are to be estimated, and I'll
> assume the errors to be normal for sake of simplicity.
>
> If there were only one response per input, I would use the nls()
> function, but what can I do in this case?

I wonder it would be sensible or at least informative to consider
solving for the "inverse case". i.e. solve for:

x = f(y1, y2)

--
David Winsemius, MD
West Hartford, CT

__
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 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 in 1:3) for(j in 1:4) print(ar34Ret(i,j),digits=15)
Error in print(ar34Ret(i, j), digits = 15) : 
  could not find function "ar34Ret"
> 

The Java code is:
public final static double[][] arReturnTEST() { 
  double[][]retArr=new double[3][4]; for(int i=0;i<3;i++)for(int
j=0;j<4;j++)retArr[i][j]=i*1000+j; return(retArr); 
} 
R doesn't know how to print the array in the next to final line,
and thinks the array is a function in the final line.

Any suggestions?


--
View this message in context: 
http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3472308.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.


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

However, whether you use merge or cbind, I think the most direct route to your 
desired result is to rename the data columns before you combine them, using the 
names function on the left hand side of an assignment with a vector of new 
names on the right.
---
Jeff Newmiller The . . Go Live...
DCN: Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Eric Fail  wrote:

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,var.M=sample(letters[5:8],10,TRUE)) DF.wave.3 <- 
data.frame(id=1:10,var.A=sample(letters[5:8],10,TRUE)) Now; I would like to 
merge the three dataframes into one, but append a suffix to the individual 
variables names about thir origin. DF.wave.all <- 
merge(DF.wave.1,DF.wave.2,DF.wave.3,by="id", [what to do here]) In other words, 
I would like it to loook like this. DF.wave.all id var.A.wave.1 var.M.wave.2 
var.A.wave.3 1 1 c h j 2 2 c e j 3 3 c g k 4 4 c e j 5 5 c g i 6 6 d e k 7 7 c 
h k 8 8 b g j 9 9 b f i 10 10 d h i Is there a command I can use directly in 
merge? 'suffixes' isn't really handy here. Thanks, 
Eric_
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] 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 typical 
GUI user environment, where the typist can highlight a group of 
characters and then begin typing. The highlighted characters disappear 
and the replacement is accomplished without changing the behavior of the 
keyboard. Many applications now attempt to guess what you want to 
highlight by performing the operation on words. To me this is not an 
advantage, for it often means that I delete one or more characters 
beyond what I wish. As Rolf noted, the adjacency of the Insert and 
Delete keys makes it far too easy to switch unwittingly to Insert mode. 
I sometimes wonder whether keyboard designers ever have to type, or 
whether they simply dictate their design inspirations into a microphone 
as some non-typists of my acquaintance do. When I received a new PC at 
work, some bright spark had placed an extra Backslash key next to the 
left Shift key _and_ reduced the size of the Shift key. After a few days 
of typing backslashes every time I wanted a capital letter, I popped 
both keys off and extended the Shift key to mostly cover the useless 
Backslash. I once programmed a special keyboard for a one-handed typist 
that allowed one to reprogram the meaning of keys, thereby accommodating 
individual preference rather than the lumbering Frankenstein of the 
average user. Now that would be a worthwhile innovation.


Jim

__
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] 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 aren't
running.Can anyone explain the meaning of this?

Here is my submit file:

# Submit file for combining the output

universe = vanilla

Executable = C:\Progra~1\R\R-2.11.1-x64\bin\Rscript.exe

getenv = true

transfer_executable = true

Output = AddTwo.out

Log = AddTwo.log

error = AddTwo.error


input = AddTwo.R

arguments = AddTwo.R

queue 
Here is my Sched Log file:

04/21 16:20:06 IWD: C:\condor\execute\dir_280

04/21 16:20:06 Input file: C:\condor\execute\dir_280\AddTwo.R

04/21 16:20:06 Output file: C:\condor\execute\dir_280\AddTwo.out

04/21 16:20:06 Error file: C:\condor\execute\dir_280\AddTwo.error

04/21 16:20:06 Renice expr "10" evaluated to 10

04/21 16:20:06 About to exec C:\condor\execute\dir_280\condor_exec.exe 
sim_boot_omega_3_1_3.R

04/21 16:20:06 Create_Process succeeded, pid=2644

04/21 16:20:06 Process exited, pid=2644, status=10
Any Ideas on this are aprreciated..

Thanks

--
View this message in context: 
http://r.789695.n4.nabble.com/return-code-10-in-the-R-documentation-tp3472470p3472470.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.


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 commented, minimal, self-contained, reproducible code.


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 when I submit the jobs on condor they aren't
running.Can anyone explain the meaning of this?

The "condor" in question appears to be a top level directory on a PC, 
not the iconic scavenger that was rescued from extinction in southern 
California. We will charitably assume that it directs your R script to 
an R interpreter at the address shown below.



Here is my submit file:

# Submit file for combining the output

universe = vanilla

Executable = C:\Progra~1\R\R-2.11.1-x64\bin\Rscript.exe


Here is a crucial bit of information.


input = AddTwo.R
...
04/21 16:20:06 Input file: C:\condor\execute\dir_280\AddTwo.R

If we could but see the code contained in "AddTwo.R" (which I strongly 
suspect is a program to add two numbers), we might be able to fathom the 
following message.


04/21 16:20:06 Process exited, pid=2644, status=10


I'll try a completely uninformed guess at your problem, which is 
probably appropriate for the completely uninformed question. "AddTwo.R" 
just might want two numbers as arguments. It adds these two numbers and 
returns the value. The "Renice..." line in the log file might indicate 
that the program is assigned low priority, and somehow this default 
argument has been returned as an error code. Please send your R code to 
the list and perhaps a more informative answer will be returned.


Jim

__
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] 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. Missing value in either dataframe
should be handled properly (i.e., just take the non-missing number
without dividing by 2).

I had a look at rowSum/Means and s/l/tapply, but couldn't figure out how
to handle this case cleanly. Any suggestions?

Thanks
Gordon

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