[R] How to reproduce heatmap.2()'s result?

2009-11-21 Thread Peng Yu
I want to understand what heatmap.2() is exactly doing. So I tried the following program. But the results by image() is still not the same as the result by heatmap.2(). Could somebody let me know how to make both results the same (in terms of the x and y axis label orders)? #

[R] How to make a matrix of a number of factors?

2009-11-22 Thread Peng Yu
I use the following code to generate a matrix of factors. I'm wondering if there is a way to make it more general so that I can have any number of factors (not necessarily 5). a=3 b=4 c=5 d=6 e=7 A=1:a B=1:b C=1:c D=1:d E=1:e X=matrix(nr=a*b*c*d*e,nc=5) for(i_a in 1:a-1) { for(i_b in 1:b-1) {

[R] How to make the assignment in a for-loop not affect variables outside the loop?

2009-11-22 Thread Peng Yu
I know that R is a dynamic programming language. But I'm wondering if there is a way to make the assignment in a for-loop not affect variables outside the loop. > n=10 > for(i in 1:n){ + n=3 + print(n) + } [1] 3 [1] 3 [1] 3 [1] 3 [1] 3 [1] 3 [1] 3 [1] 3 [1] 3 [1] 3 > > print(n) [1] 3 > __

[R] Why F value and Pr are not show in summary() of an aov() result?

2009-11-22 Thread Peng Yu
I have the following code. I'm wondering why summary() doesn't show F value and Pr? Rscript multi_factor.R > a=3 > b=4 > c=5 > d=6 > e=7 > > A=1:a > B=1:b > C=1:c > D=1:d > E=1:e > > X=matrix(nr=a*b*c*d*e,nc=5) > colnames(X)=LETTERS[1:5] > > for(i_a in 1:a-1) { + for(i_b in 1:b-1) { + for(i_

[R] How to get the factor level means with interaction term?

2009-11-22 Thread Peng Yu
I thought that the last two statements in the following code should give me the same results (what I want are the factor level means for factor 'A'). But they don't. I think that the last statement should give me the correct factor level means for 'A'. Could somebody let me know what the problems

[R] where is lme() that is referred by aov() help page?

2009-11-22 Thread Peng Yu
The help page of aov() mentions lme(). Does it refer to lme() in package nlme? __ 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 comm

Re: [R] where is lme() that is referred by aov() help page?

2009-11-22 Thread Peng Yu
On Sun, Nov 22, 2009 at 2:42 PM, Duncan Murdoch wrote: > On 22/11/2009 3:38 PM, Peng Yu wrote: >> >> The help page of aov() mentions lme(). Does it refer to lme() in package >> nlme? > > Yes, that's where the link takes you. Should this information be mentioned

[R] How to change line width in heatmap.2()?

2009-11-22 Thread Peng Yu
I don't see an option to tune linewdith in heatmap.2(). Could somebody let me know how to tune the dendrogram line width? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-proj

Re: [R] Understanding hclust and dendrogram

2009-11-24 Thread Peng Yu
On Thu, Oct 15, 2009 at 4:11 AM, Fearghas MacGregor wrote: > I'd recommend "The Elements of Statistical Learning" by Hastie, Tibshirani, > and Friedman. There's a lot of good information on clustering, as well as a > wealth of info on many other apsects of classification, machine learning, > etc.

[R] How to get the item in list that is a number?

2009-11-24 Thread Peng Yu
I have the following list. The second item in the list is a number. I'm wondering how to write R code to return this information for any list? $`1` integer(0) $`2` [1] 123 $`3` integer(0) $`4` integer(0) $`5` integer(0) __ R-help@r-project.org mail

[R] XML package example code?

2009-11-24 Thread Peng Yu
I'm interested in parsing an html page. I should use XML, right? Could you somebody show me some example code? Is there a tutorial for this package? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the post

Re: [R] XML package example code?

2009-11-25 Thread Peng Yu
On Wed, Nov 25, 2009 at 12:19 AM, cls59 wrote: > > > Peng Yu wrote: >> >> I'm interested in parsing an html page. I should use XML, right? Could >> you somebody show me some example code? Is there a tutorial for this >> package? >> > > Did

[R] How to suppress errors generated by readHTMLTable?

2009-11-26 Thread Peng Yu
library(XML) download.file('http://polya.umdnj.edu/polya_db2/gene.php?llid=109079&unigene=&submit=Submit','index.html') tables=readHTMLTable("index.html",error=function(...){}) tables readHTMLTable gives me the following errors. Could somebody let me know how to suppress them? Opening and endi

[R] How to combine matrix with sapply function?

2009-11-27 Thread Peng Yu
I want an 'apply' function that can give me results by bind the result from each function call of g. Could somebody let me know how to do it? g<-function(x){ if(x==1){ rbind(c(1,3,8)) } else if(x==2) { rbind(c(4,7,2), c(3,7,3)) #if I use line, sapply() below gives me a list #rbind(

[R] How to find where the source code of an R function or package is installed?

2009-11-28 Thread Peng Yu
I'm wondering where is the source of an R function or a package is. For example, where is 'attributes'? > attributes function (obj) .Primitive("attributes") I also do understand what .Primitive mean. Could somebody let me know how to locate source file in an R installation? Why typing 'attribute

Re: [R] What is the equivalent of column.prods() from S in R?

2009-11-28 Thread Peng Yu
On Mon, Nov 9, 2009 at 8:35 PM, David Winsemius wrote: > > On Nov 9, 2009, at 8:43 PM, Peng Yu wrote: > >> Chambers' book Statistical Models in S mentioned 'column.prods()'. But >> I don't find it in R. I'm wondering if there is an equivalent in R

Re: [R] What is the equivalent of column.prods() from S in R?

2009-11-28 Thread Peng Yu
On Sat, Nov 28, 2009 at 11:00 PM, David Winsemius wrote: > > On Nov 28, 2009, at 11:28 PM, Peng Yu wrote: > >> On Mon, Nov 9, 2009 at 8:35 PM, David Winsemius >> wrote: >>> >>> On Nov 9, 2009, at 8:43 PM, Peng Yu wrote: >>> >>>> Ch

[R] Rules for coding expanded formulas

2009-11-29 Thread Peng Yu
I'm reading Section 2.4.1 Rules for Coding Expanded Formulas in Statistical Models in S by Chambers and Hastie. It is a little abstract for me. Could somebody point me some references that have more examples and more explanations that can help me understand the rules (in particular, the ones on pag

[R] Why .Diag and .asSparse are not accessible in R sessions?

2009-11-29 Thread Peng Yu
'.Diag' and '.asSparse' are defined in contrast.R. I'm wondering why I don't see them in my R session. Is it because that they start with '.'? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting gu

[R] What are polynomial contrasts?

2009-11-29 Thread Peng Yu
I don't find a good explanation on polynomial contrasts. Could somebody recommend one to me? __ 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 an

Re: [R] Why .Diag and .asSparse are not accessible in R sessions?

2009-11-29 Thread Peng Yu
How to control what functions/classes are exported to a given namespace? On Sun, Nov 29, 2009 at 3:34 PM, baptiste auguie wrote: > Hi, > > They're not exported from the stats namespace, > > stats:::.Diag > stats:::.asSparse > > ?":::" > > HTH, > &g

[R] vector as data.frame element?

2009-11-30 Thread Peng Yu
It seems that an vector or other non elemental data type can not be assigned to an element in the data.frame. I'm wondering what is the walk around. > li=data.frame(a=c(0,1), b=c('x','y')) > li$b[[1]]= 'x' > li$b[[2]]<- c('y','z') Error in li$b[[2]] <- c("y", "z") : more elements supplied than t

[R] Is there a function to test if all the elements in a vector are unique

2009-11-30 Thread Peng Yu
length(unique(c(1,2,2)))==length(c(1,2,2)) I use the above test to test if all the elements in a vector are unique. But I'm wondering if there is a convenient function to do so in R library. __ R-help@r-project.org mailing list https://stat.ethz.ch/mail

[R] apply on two lists?

2009-11-30 Thread Peng Yu
x=list(a=c(1,2),b=c(3,4,5)) y=list(a=c(1,2),b=c(3,4,5)) lapply(seq(along=x),function(i){cbind(x[[i]],y[[i]])}) I need to apply some function on two lists. I have to use the index to do as shown above. But I feel more natural to refer to the lists without using the index (using the syntax of somet

[R] go back a block of code in history

2009-11-30 Thread Peng Yu
Suppose I run the following code in the R session. At the last prompt '>', I want to retrieve the second command (staring with 'y'). But I have to type up arrow many times, which is very inconvenient. I'm wondering if there is a way to configure R to skip block of code in the history? > x=list(a=c

[R] About the method dispatch mechanism

2009-11-30 Thread Peng Yu
I see the follow explanation in help(cbind). I don't understand what the dispatch mechanism is. Could you point me what document or reference I should read? The method dispatching is _not_ done via 'UseMethod()', but by C-internal dispatching. Therefore, there is no need for, e.g.,

Re: [R] How to quit unwanted execution immediately?

2009-12-01 Thread Peng Yu
there are more or > less regular checks for events such as this one. > If you are using some contributed package, it may be an issue in this > package's source code. > > Best wishes, > Uwe Ligges > > > > > Peng Yu wrote: >> >> Occasionally, I start

[R] How to compute contrast where there are interaction terms in the linear model?

2009-12-01 Thread Peng Yu
Could somebody recommend some textbook how to compute contrast when there are interactions terms? "Applied Linear Regression Models" (book) mentioned contrast, but I cannot extend it to the case where there are interaction terms. __ R-help@r-project.org

Re: [R] Is there a function to test if all the elements in a vector are unique

2009-12-01 Thread Peng Yu
On Tue, Dec 1, 2009 at 1:40 AM, Karl Ove Hufthammer wrote: > On Tue, 1 Dec 2009 14:48:04 +1100 Remko Duursma > wrote: >> any(duplicated(c(1,2,2))) > > or > anyDuplicated(c(1,2,2)) > which is slightly more efficient. I don't find anyDuplicated(). Which package is it from? ___

Re: [R] Is there a function to test if all the elements in a vector are unique

2009-12-01 Thread Peng Yu
On Tue, Dec 1, 2009 at 7:46 PM, Jorge Ivan Velez wrote: > Try this: > R> apropos('any') > R> ?anyDuplicated > HTH, > Jorge > > On Tue, Dec 1, 2009 at 8:32 PM, Peng Yu wrote: >> >> On Tue, Dec 1, 2009 at 1:40 AM, Karl Ove Hufthammer >> wrot

Re: [R] Is there a function to test if all the elements in a vector are unique

2009-12-01 Thread Peng Yu
ia a namespace (and not attached): > [1] tools_2.10.0 > HTH, > Jorge > On Tue, Dec 1, 2009 at 8:57 PM, Peng Yu wrote: >> >> On Tue, Dec 1, 2009 at 7:46 PM, Jorge Ivan Velez >> wrote: >> > Try this: >> > R> apropos('any') >> >

Re: [R] Is there a function to test if all the elements in a vector are unique

2009-12-01 Thread Peng Yu
On Tue, Dec 1, 2009 at 8:24 PM, Rolf Turner wrote: > > On 2/12/2009, at 3:09 PM, Peng Yu wrote: > >         > >> Here is my sessionInfo(). > >        [Snotty comment deleted.] > >>> sessionInfo() >> >> R version 2.7.1 (2008-06-23) > >    

[R] How to remove R banner?

2009-12-01 Thread Peng Yu
I always see a banner like the following, which is annoying. I'm wondering how to disable it. R version 2.7.1 (2008-06-23) Copyright (C) 2008 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it

[R] How to export a function from a package and access it only by specifying the namespace?

2009-12-01 Thread Peng Yu
I have the following test package. $ ls DESCRIPTION man NAMESPACE R $ cat DESCRIPTION Package: try.package Type: Package Title: What the package does (short line) Version: 1.0 Date: 2009-10-26 Author: Who wrote it Maintainer: Who to complain to Description: More about what it does (maybe more

Re: [R] How to export a function from a package and access it only by specifying the namespace?

2009-12-02 Thread Peng Yu
On Tue, Dec 1, 2009 at 11:27 PM, Sharpie wrote: > > > Peng Yu wrote: >> >> Then I try the package 'try.package' in an R session. I'm wondering >> why neither 'my_test_f' and 'try.package::my_test_f' work. >> > >

[R] documentation of intersect() on string vector and num vector and on duplicated elements

2009-12-02 Thread Peng Yu
> intersect(c(1,3,2),c('1','3')) [1] "1" "3" Apparently, intersect() treats num as string. But this is not documented in the help. Could somebody add it in the future version of R? Also according to the help, the argument should not have duplicated elements. But I tried the following example, it

Re: [R] documentation of intersect() on string vector and num vector and on duplicated elements

2009-12-02 Thread Peng Yu
On Wed, Dec 2, 2009 at 3:51 PM, David Winsemius wrote: > On Dec 2, 2009, at 4:33 PM, Peng Yu wrote: > >>> intersect(c(1,3,2),c('1','3'))   # note x is numeric and y is character >> >> [1] "1" "3" >> >> Apparently, int

Re: [R] documentation of intersect() on string vector and num vector and on duplicated elements

2009-12-02 Thread Peng Yu
On Wed, Dec 2, 2009 at 5:36 PM, Peter Ehlers wrote: > > Peng Yu wrote: >> >> On Wed, Dec 2, 2009 at 3:51 PM, David Winsemius >> wrote: >>> >>> On Dec 2, 2009, at 4:33 PM, Peng Yu wrote: >>> >>>>> intersect(c(1,3,2),c('

[R] How to step in a function?

2009-12-02 Thread Peng Yu
To debug a function, what I currently know is to put 'browser()' in it. But I'm wondering if there is a way like 'step in' that is available in debuggers of other languages (e.g. gdb). __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/lis

Re: [R] How to step in a function?

2009-12-02 Thread Peng Yu
On Wed, Dec 2, 2009 at 8:08 PM, David Winsemius wrote: > > On Dec 2, 2009, at 8:58 PM, Peng Yu wrote: > >> To debug a function, what I currently know is to put 'browser()' in >> it. But I'm wondering if there is a way like 'step in' that is >>

Re: [R] How to step in a function?

2009-12-02 Thread Peng Yu
On Wed, Dec 2, 2009 at 10:12 PM, David Winsemius wrote: > > On Dec 2, 2009, at 10:54 PM, Peng Yu wrote: > >> On Wed, Dec 2, 2009 at 8:08 PM, David Winsemius >> wrote: >>> >>> On Dec 2, 2009, at 8:58 PM, Peng Yu wrote: >>> >>>> To debu

[R] Naming conventions for R?

2009-12-03 Thread Peng Yu
There are documents for naming conventions for other languages. I'm wondering if there is a document that clearly describes the recommended naming convention for R. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE

[R] How to exclude lines that match certain regex when using read.table?

2009-12-03 Thread Peng Yu
I'm thinking of using external program 'grep' and pipe() to do so. But I'm wondering if there is a more efficient way to do so purely in R __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide

Re: [R] Naming conventions for R?

2009-12-03 Thread Peng Yu
On Thu, Dec 3, 2009 at 8:27 PM, Sharpie wrote: > > > pengyu.ut wrote: >> >> There are documents for naming conventions for other languages. I'm >> wondering if there is a document that clearly describes the >> recommended naming convention for R. >> > > > You should browse this thread: > >  http:/

[R] shorten str() output for long list

2009-12-03 Thread Peng Yu
> x=split(1:1000,1:1000) > str(x) Although str() can suppress long output for vectors, but it can not suppress long output for list. I'm wondering how to suppress the output for long lists. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailm

Re: [R] How to exclude lines that match certain regex when using read.table?

2009-12-03 Thread Peng Yu
On Thu, Dec 3, 2009 at 9:09 PM, Sharpie wrote: > > > pengyu.ut wrote: >> >> I'm thinking of using external program 'grep' and pipe() to do so. But >> I'm wondering if there is a more efficient way to do so purely in R >> > > I would just suck the whole table in using read.table(), locate the lines

[R] How to get a matrix by sapply (with strsplit)?

2009-12-03 Thread Peng Yu
I want a command (last line) that can return a matrix. I'm wondering if there is a way to do so. g<-function(x) { c(x,x) } lapply(1:10,g) sapply(1:10,g) sapply(paste(1:10, 1:10), strsplit, split=' ')# I want a command that returns a matrix __ R-help@

[R] Speed of accessing list element by index or name

2009-12-03 Thread Peng Yu
I'm wondering if the speed of accessing list element by index is the same as that of accessing list element by name. l[[1]] l[['name']] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide ht

Re: [R] shorten str() output for long list

2009-12-03 Thread Peng Yu
On Fri, Dec 4, 2009 at 12:18 AM, David Winsemius wrote: > > On Dec 3, 2009, at 10:11 PM, Peng Yu wrote: > >>> x=split(1:1000,1:1000) >>> str(x) >> >> Although str() can suppress long output for vectors, but it can not >> suppress long output for list

Re: [R] How to compute contrast where there are interaction terms in the linear model?

2009-12-04 Thread Peng Yu
On Tue, Dec 1, 2009 at 4:04 PM, Charles C. Berry wrote: > On Tue, 1 Dec 2009, Peng Yu wrote: > >> Could somebody recommend some textbook how to compute contrast when >> there are interactions terms? "Applied Linear Regression Models" >> (book) mentioned contr

[R] grep() exclude certain patterns?

2009-12-04 Thread Peng Yu
The external grep program has an option -v to select non-matching lines. I'm wondering if how to exclude certain patterns in grep() in R? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide h

Re: [R] grep() exclude certain patterns?

2009-12-04 Thread Peng Yu
On Fri, Dec 4, 2009 at 11:54 AM, Duncan Murdoch wrote: > On 04/12/2009 12:52 PM, Peng Yu wrote: >> >> The external grep program has an option -v to select non-matching >> lines. I'm wondering if how to exclude certain patterns in grep() in >> R? >> > &

[R] How to duplicate each row in a data.frame?

2009-12-04 Thread Peng Yu
I want to duplicate each line in 'df' 3 times. But I'm confused why 'z' is a 6 by 4 matrix. Could somebody let me know what the correct way is to duplicate each row of a data.frame? df=expand.grid(x1=c('a','b'),x2=c('u','v')) n=3 z=apply(df,1 ,function(x){ result=do.call(rbind,rep(list(x

Re: [R] grep() exclude certain patterns?

2009-12-04 Thread Peng Yu
above are my current thoughts. Let me know if it makes sense to you or not. >> -Original Message- >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- >> project.org] On Behalf Of Peng Yu >> Sent: Friday, December 04, 2009 12:43 PM >> To: r-h...@stat.math.et

Re: [R] grep() exclude certain patterns?

2009-12-04 Thread Peng Yu
On Fri, Dec 4, 2009 at 3:06 PM, Peng Yu wrote: > On Fri, Dec 4, 2009 at 2:35 PM, Greg Snow wrote: >> The invert argument seems a likely candidate, you could also do perl=TRUE >> and use negations within the pattern (but that is probably overkill for your >> original quest

Re: [R] How to compute contrast where there are interaction terms in the linear model?

2009-12-04 Thread Peng Yu
On Fri, Dec 4, 2009 at 12:18 PM, Charles C. Berry wrote: > On Fri, 4 Dec 2009, Peng Yu wrote: > >> On Tue, Dec 1, 2009 at 4:04 PM, Charles C. Berry >> wrote: >>> >>> On Tue, 1 Dec 2009, Peng Yu wrote: >>> >>>> Could somebody recommend

Re: [R] grep() exclude certain patterns?

2009-12-04 Thread Peng Yu
On Fri, Dec 4, 2009 at 7:51 PM, Charles C. Berry wrote: > On Fri, 4 Dec 2009, Peng Yu wrote: > >> On Fri, Dec 4, 2009 at 2:35 PM, Greg Snow wrote: >>> >>> The invert argument seems a likely candidate, you could also do perl=TRUE >>> and use negations w

[R] data.frame is slower than matrix?

2009-12-08 Thread Peng Yu
I'm doing some data manipulations. I thought originally that I should use data.frame, as the elements in a data.frame can have multiple types but the elements in a matrix has to be the same, which all the data have to convert to strings if there is a single column that is string. However, when I

Re: [R] grep() exclude certain patterns?

2009-12-08 Thread Peng Yu
ort was > made, what restrictions you are working under, and other details), I bet that > you would have something productive by now. > > See further comments interspersed below: > > > >> -Original Message- >> From: r-help-boun...@r-project.org [ma

Re: [R] grep() exclude certain patterns?

2009-12-08 Thread Peng Yu
On Fri, Dec 4, 2009 at 6:12 PM, Gavin Simpson wrote: > On Fri, 2009-12-04 at 15:18 -0600, Peng Yu wrote: >> On Fri, Dec 4, 2009 at 3:06 PM, Peng Yu wrote: >> > On Fri, Dec 4, 2009 at 2:35 PM, Greg Snow wrote: >> >> The invert argument seems a likely candidat

[R] Significant performance difference between split of a data.frame and split of vectors

2009-12-08 Thread Peng Yu
I have the following code, which tests the split on a data.frame and the split on each column (as vector) separately. The runtimes are of 10 time difference. When m and k increase, the difference become even bigger. I'm wondering why the performance on data.frame is so bad. Is it a bug in R? Can i

[R] Can elements of a list be passed as multiple arguments?

2009-12-08 Thread Peng Yu
I want to split a matrix, where both 'u' and 'w' are results of possible ways. However, whenever 'n' changes, the argument passed to mapply() has to change. Is there a way to pass elements of a list as multiple arguments? m=10 n=2 k=3 set.seed(0) x=replicate(n,rnorm(m)) f=sample(1:k, size=m, repl

[R] How to know what vignette are available in a package?

2009-12-08 Thread Peng Yu
For any given package (for example, data.table), is there a way to show all the available vignette from the package (or to know whether there is vignette)? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read t

Re: [R] Significant performance difference between split of a data.frame and split of vectors

2009-12-08 Thread Peng Yu
On Tue, Dec 8, 2009 at 10:37 PM, David Winsemius wrote: > > On Dec 8, 2009, at 11:28 PM, Peng Yu wrote: > >> I have the following code, which tests the split on a data.frame and >> the split on each column (as vector) separately. The runtimes are of >> 10 time differ

[R] Warning for data.table (with ref)?

2009-12-09 Thread Peng Yu
I have following the message "dim(refdata) and dimnames(refdata) no longer allow parameter ref=TRUE, use dim(derefdata(refdata)), dimnames(derefdata(refdata)) instead" when I loaded data.table. Is it from the package ref? Could it be fixed? Or there is something wrong with my installation? > libra

Re: [R] Significant performance difference between split of a data.frame and split of vectors

2009-12-09 Thread Peng Yu
On Tue, Dec 8, 2009 at 11:06 PM, David Winsemius wrote: > > On Dec 9, 2009, at 12:00 AM, Peng Yu wrote: > >> On Tue, Dec 8, 2009 at 10:37 PM, David Winsemius >> wrote: >>> >>> On Dec 8, 2009, at 11:28 PM, Peng Yu wrote: >>> >>>> I ha

Re: [R] Can elements of a list be passed as multiple arguments?

2009-12-09 Thread Peng Yu
On Tue, Dec 8, 2009 at 11:05 PM, David Winsemius wrote: > > On Dec 8, 2009, at 11:37 PM, Peng Yu wrote: > >> I want to split a matrix, where both 'u' and 'w' are results of >> possible ways. However, whenever 'n' changes, the argument passed t

Re: [R] Significant performance difference between split of a data.frame and split of vectors

2009-12-09 Thread Peng Yu
On Wed, Dec 9, 2009 at 11:20 AM, Charles C. Berry wrote: > On Wed, 9 Dec 2009, Peng Yu wrote: > >> On Tue, Dec 8, 2009 at 11:06 PM, David Winsemius >> wrote: >>> >>> On Dec 9, 2009, at 12:00 AM, Peng Yu wrote: >>> >>>> On Tue,

Re: [R] Significant performance difference between split of a data.frame and split of vectors

2009-12-09 Thread Peng Yu
On Tue, Dec 8, 2009 at 10:37 PM, David Winsemius wrote: > > On Dec 8, 2009, at 11:28 PM, Peng Yu wrote: > >> I have the following code, which tests the split on a data.frame and >> the split on each column (as vector) separately. The runtimes are of >> 10 time differ

[R] What is the development cycle where there are code in tests/ for package development?

2009-12-09 Thread Peng Yu
I see 'library(stats)' at the beginning of R-2.10.0/src/library/stats/tests/nls.R. I'm wondering if I am developing my own package 'mypackage' whether I should put 'library(mypackage)' in a .R file in mypackage/tests/? If I do, then it seems awkward to me, because to use 'library(mypackage)', I ha

[R] How to figure out which the version of split is used?

2009-12-09 Thread Peng Yu
There are a number of functions that are dispatched to from split(). > methods('split') [1] split.data.frame split.Date split.defaultsplit.POSIXct Is there a way to figure out which of these variants is actually dispatched to when I call split? I know that if the argument is of the type

Re: [R] [Rd] split() is slow on data.frame (PR#14123)

2009-12-09 Thread Peng Yu
I make a version for matrix. Because, it would be more efficient to split each column of a matrix than to convert a matrix to a data.frame then call split() on the data.frame. Note that the version for a matrix and a data.frame is slightly different. Would somebody add this in R as well? split.mat

Re: [R] [Rd] split() is slow on data.frame (PR#14123)

2009-12-09 Thread Peng Yu
Sorry. I sent this to r-help by mistake. Could somebody help delete it from the archive? On Wed, Dec 9, 2009 at 9:29 PM, Peng Yu wrote: > I make a version for matrix. Because, it would be more efficient to > split each column of a matrix than to convert a matrix to a data.frame > then c

Re: [R] How to make the assignment in a for-loop not affect variables outside the loop?

2009-12-09 Thread Peng Yu
nction(){ >    for(i in 1:n){ >        n <- 3 >        print(n) >    } > } > > MyLoopFoo() > > print(n) > > > > > Uwe Ligges > > > Peng Yu wrote: >> >> I know that R is a dynamic programming language. But I'm wondering if >> there

[R] What is the function to test if a vector is ordered or not?

2009-12-09 Thread Peng Yu
I did a search on www.rseek.org to look for the function to test if a vector is ordered or not. But I don't find it. Could somebody let me know what function I should use? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help

[R] About R memory management?

2009-12-10 Thread Peng Yu
I'm wondering where I can find the detailed descriptions on R memory management. Understanding this could help me understand the runtime of R program. For example, depending on how memory is allocated (either allocate a chuck of memory that is more than necessary for the current use, or allocate th

Re: [R] About R memory management?

2009-12-10 Thread Peng Yu
. > > Rule of thumb: > Pre-allocate your object of the *correct* data type, if you know the > final dimensions. > > /Henrik > > On Thu, Dec 10, 2009 at 8:26 AM, Peng Yu wrote: >> I'm wondering where I can find the detailed descriptions on R memory >> manag

Re: [R] How to figure out which the version of split is used?

2009-12-10 Thread Peng Yu
On Thu, Dec 10, 2009 at 3:46 AM, Karl Ove Hufthammer wrote: > On Wed, 9 Dec 2009 19:20:47 -0600 Peng Yu wrote: >> Is there a way to figure out which of these variants is actually >> dispatched to when I call split? I know that if the argument is of the >> type data.frame,

[R] Is there a variant of findInterval() such that v[i[j]] < x[j] <= v[i[j] + 1]?

2009-12-10 Thread Peng Yu
In findInterval's help page, it says 'v[i[j]] <= x[j] < v[i[j] + 1]'. I'm wondering if there is a variant of it such that 'v[i[j]] < x[j] <= v[i[j] + 1]'. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read th

[R] How to get the runtime as well as the result?

2009-12-10 Thread Peng Yu
If I use system.time() to measure the runtime of an expression, I will not get the result. Is there a way to measure the runtime and get the result as well? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read

Re: [R] About R memory management?

2009-12-10 Thread Peng Yu
tion of this; preallocate and then extend when you read a > limit > x <- numeric(2) > for (i in 1:100){ >     if (i > length(x)){ >     # double the length (or whatever you want) >     length(x) <- length(x) * 2 >     } >     x[i] <- i > } > >

Re: [R] How to get the runtime as well as the result?

2009-12-10 Thread Peng Yu
On Thu, Dec 10, 2009 at 7:03 PM, Dirk Eddelbuettel wrote: > > On 10 December 2009 at 18:12, Peng Yu wrote: > | If I use system.time() to measure the runtime of an expression, I will > | not get the result. Is there a way to measure the runtime and get the > | result as well? > &

[R] How to profile an R program?

2009-12-10 Thread Peng Yu
Is there a way to profile an R program similar to valgrind (valgrind.org), in the sense that I can easily see which function is the bottleneck of an R program? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do re

[R] How to get rid of NULL in the result of apply()?

2009-12-10 Thread Peng Yu
The following code returns a list with the 2nd element as NULL. I'm wondering what the best way to get rid of NULL element in an 'apply()'s result. > lapply(1:3, function(x) { + if(x==2) { + return(NULL) + } else { + return(x) + } + } + ) [[1]] [1] 1 [[2]

Re: [R] How to get rid of NULL in the result of apply()?

2009-12-10 Thread Peng Yu
On Thu, Dec 10, 2009 at 10:00 PM, Marc Schwartz wrote: > On Dec 10, 2009, at 9:44 PM, Peng Yu wrote: > >> The following code returns a list with the 2nd element as NULL. I'm >> wondering what the best way to get rid of NULL element in an >> 'apply()'

[R] Why a list of NULL's are reduced to NULL?

2009-12-11 Thread Peng Yu
The following examples are confusing to me. It is OK, to assigned NULL to one element in a list. The result is still a list. However, a list of NULL's are reduced to NULL. I don't understand how this conversion occurs. Could somebody let me know what is going on? > X=matrix(1:8, nr=4) > apply(X,1,

[R] The correct way to set an element in a list to NULL? (FAQ is not clear)

2009-12-11 Thread Peng Yu
http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-set-components-of-a-list-to-NULL_003f The explanation on this FAQ entry is not clear. It says '... similarly for named components...'. What I understood was x[i]<-list(NULL) is the same as x$a_name<-list(NULL). But, they are not. As the exampl

Re: [R] Why a list of NULL's are reduced to NULL?

2009-12-11 Thread Peng Yu
On Fri, Dec 11, 2009 at 11:01 AM, William Dunlap wrote: >> -Original Message- >> From: r-help-boun...@r-project.org >> [mailto:r-help-boun...@r-project.org] On Behalf Of Peng Yu >> Sent: Friday, December 11, 2009 8:44 AM >> To: r-h...@stat.math.ethz.ch >&g

Re: [R] The correct way to set an element in a list to NULL? (FAQ is not clear)

2009-12-11 Thread Peng Yu
On Fri, Dec 11, 2009 at 11:27 AM, Steve Lianoglou wrote: > Hi, > > On Dec 11, 2009, at 12:07 PM, Peng Yu wrote: > >> http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-set-components-of-a-list-to-NULL_003f >> >> The explanation on this FAQ entry is not clear.

Re: [R] Why a list of NULL's are reduced to NULL?

2009-12-11 Thread Peng Yu
On Fri, Dec 11, 2009 at 11:43 AM, William Dunlap wrote: >> -Original Message- >> From: r-help-boun...@r-project.org >> [mailto:r-help-boun...@r-project.org] On Behalf Of Peng Yu >> Sent: Friday, December 11, 2009 9:18 AM >> To: r-h...@stat.math.ethz.ch >

Re: [R] The correct way to set an element in a list to NULL? (FAQ is not clear)

2009-12-11 Thread Peng Yu
On Fri, Dec 11, 2009 at 11:51 AM, Steve Lianoglou wrote: > > On Dec 11, 2009, at 12:36 PM, Peng Yu wrote: > [snip] > >>>> What seems confusing to me is: >>>> even 'x[i]<-list(NULL)' and 'x[[i]]<-list(NULL)' are different, why >>

Re: [R] Why a list of NULL's are reduced to NULL?

2009-12-11 Thread Peng Yu
On Fri, Dec 11, 2009 at 12:05 PM, hadley wickham wrote: >> A very common situation is that the users don't know all the possible >> return types of 'some_third_party_function()'. If the users don't know >> all the return types, he/she can not make sure the return type of >> function(x) {...} be al

Re: [R] Why a list of NULL's are reduced to NULL?

2009-12-11 Thread Peng Yu
tion at the language level? Perl has a strict mode and a non strict mode. If it is always better to return the same type, which is the case in other strong typed language, then it might better that there is such a mode in R to enforce the same return type. > At 12:24 PM -0600 12/11/09, Peng Yu

Re: [R] Why a list of NULL's are reduced to NULL?

2009-12-11 Thread Peng Yu
On Fri, Dec 11, 2009 at 2:37 PM, Charlie Sharpsteen wrote: > On Fri, Dec 11, 2009 at 10:24 AM, Peng Yu wrote: >> >> How do you figure out all the possibilities? > > Well, the "Value" section of the third party function's help page should > outline the r

Re: [R] Why a list of NULL's are reduced to NULL?

2009-12-11 Thread Peng Yu
On Fri, Dec 11, 2009 at 3:49 PM, Steve Lianoglou wrote: > > On Dec 11, 2009, at 4:45 PM, Peng Yu wrote: > >> On Fri, Dec 11, 2009 at 2:37 PM, Charlie Sharpsteen >> wrote: >>> On Fri, Dec 11, 2009 at 10:24 AM, Peng Yu wrote: >>>> >>>> How

[R] Is there lazy copy in R?

2009-12-14 Thread Peng Yu
I'm wondering if lazy copy is available in R or not. For example, in the following code, I'm wondering if the memory for y is allocated in the 2nd line or the 3rd line. Is there a documentation for this? x=1:1 y=x y[[10]]=5 __ R-help@r-project.org m

Re: [R] Is there lazy copy in R?

2009-12-14 Thread Peng Yu
Would you please help me understand it? On Mon, Dec 14, 2009 at 9:23 PM, Benilton Carvalho wrote: > use tracemem() to figure out... and read its documentation in detail. > b > > > On Dec 15, 2009, at 1:03 AM, Peng Yu wrote: > >> I'm wondering if lazy copy is available i

Re: [R] Is there lazy copy in R?

2009-12-15 Thread Peng Yu
On Tue, Dec 15, 2009 at 10:32 PM, hadley wickham wrote: >> I don't understand what these addresses mean. Would you please help me >> understand it? > > Did you try reading the documentation? > >     When an object is traced any copying of the object by the C >     function ‘duplicate’ or by arithm

Re: [R] Is there lazy copy in R?

2009-12-15 Thread Peng Yu
2009/12/15 : > On Wed, 16 Dec 2009, Peng Yu wrote: > >> On Tue, Dec 15, 2009 at 10:32 PM, hadley wickham >> wrote: >>>> >>>> I don't understand what these addresses mean. Would you please help me >>>> understand it? >>> >

[R] 'tracemem' question when I change the length of a vector

2009-12-15 Thread Peng Yu
Please see the following example. If I change the length of a vector twice below, I don't understand why 'tracemem' is shown in the first case but not the second case. Could somebody help explain it to me? > x=1 > tracemem(x) [1] "<0x1bad8c8>" > length(x)=100# The 'tracemem' string is shown as exp

<    1   2   3   4   >