[R] residuals of glm

2014-09-29 Thread Yuan Jian
Hello, I found the residuals of glm is not the same as calculated manually. >y=c(12,14,33,50,67,74,123,141,165,204,253,246,240) > t=1:13 > m1=glm(y~t+I(t^2),family=poisson(link="log")) > coefficients(m1)[1]+coefficients(m1)[2]*log(t)+coefficients(m1)[3]*log(t^2) [1] 1.901459 2.257258 2.465388 2.6

[R] cbind in data.frame

2008-08-24 Thread Yuan Jian
hi, when I used cbind to combine columns, some contents of columns has been replaced by number. in the script below, column should be aaa,bbb,ccc but I was given 1,2,3. but when I change the column to vector, it gave me correct contents. can you please tell me why?   > d<-read.table("aaa.txt") >

Re: [R] cbind in data.frame

2008-08-25 Thread Yuan Jian
lt;[EMAIL PROTECTED]> Subject: Re: [R] cbind in data.frame To: r-help@r-project.org Date: Monday, August 25, 2008, 6:09 AM Le Sun, Aug 24, 2008 at 10:56:43PM -0700, Yuan Jian a écrit : > hi, > when I used cbind to combine columns, some contents of columns has been replaced by > number

[R] add to vector without duplicatation

2008-08-27 Thread Yuan Jian
Hi,   I try to add items to a vector, but when the it has existed, the item should be skipped. does anyone know how to do it a simple way?     Yu [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.eth

[R] lost attrubute:names

2008-08-28 Thread Yuan Jian
Hi, when I pick out one element from a matrix, the attribute name is kept, but when more than one elements are extracted, the attribute name lost;   >a<-matrix(c(1,2,3,11,12,13,45,56,76),ncol=3,dimnames=list(c(),c("c1","c2","c3"))) > k<-a[a[,"c3"]>50,"c3"] > kk<-a[a[,"c3"]>60,"c3"] > attributes(k)

[R] remove levels from a factor

2008-08-29 Thread Yuan Jian
Hi,   how to remove levels that have less than a specific number such as 2. i.e..   > f<-as.factor(c("a","b","a")) > f [1] a b a Levels: a b I want to remove level b because level b has less than 2. > f [1] a a Levels: a   [[alternative HTML version deleted]] __

[R] remove low frequent rows

2008-08-30 Thread Yuan Jian
Hi,   I have a matrix. >a<-cbind(c("a","b","a"),c(4,3,6)) [,1] [,2] [1,] "a"  "4" [2,] "b"  "3" [3,] "a"  "6" I want to remove rows in matrix a whose first column has frequency less than 2. in about example matrix a becomes [,1] [,2] [1,] "a"  "4" [2,] "a"  "6" [[

[R] give all combinations

2008-08-31 Thread Yuan Jian
Hello,   is there a simple way to give all combinations for a given vector:   v<-c("a","b","c")   combination(v,v) becomes "aa","ab","ac","bb","bc","cc'   combination(v,v,v) becomes "aaa","aab","aac","abb",..     [[alternative HTML version deleted]] ___

Re: [R] give all combinations

2008-08-31 Thread Yuan Jian
hould be aa, ab, ac, bc    --- On Sun, 8/31/08, Lucien Lemmens <[EMAIL PROTECTED]> wrote: From: Lucien Lemmens <[EMAIL PROTECTED]> Subject: Re: [R] give all combinations To: [EMAIL PROTECTED] Date: Sunday, August 31, 2008, 8:38 AM Yuan Jian yahoo.com> writes: > > Hello, &g

Re: [R] give all combinations

2008-08-31 Thread Yuan Jian
;) v v should be aa, ab, ac, bc    --- On Sun, 8/31/08, Lucien Lemmens <[EMAIL PROTECTED]> wrote: From: Lucien Lemmens <[EMAIL PROTECTED]> Subject: Re: [R] give all combinations To: [EMAIL PROTECTED] Date: Sunday, August 31, 2008, 8:38 AM Yuan Jian yahoo.com> writes: > > Hello,

Re: [R] give all combinations

2008-08-31 Thread Yuan Jian
hould be aa, ab, ac, bc    --- On Sun, 8/31/08, Lucien Lemmens <[EMAIL PROTECTED]> wrote: From: Lucien Lemmens <[EMAIL PROTECTED]> Subject: Re: [R] give all combinations To: [EMAIL PROTECTED] Date: Sunday, August 31, 2008, 8:38 AM Yuan Jian yahoo.com> writes: > > Hello, &g

Re: [R] give all combinations

2008-08-31 Thread Yuan Jian
"a","b","c") v v should be aa, ab, ac, bc    --- On Sun, 8/31/08, Lucien Lemmens <[EMAIL PROTECTED]> wrote: From: Lucien Lemmens <[EMAIL PROTECTED]> Subject: Re: [R] give all combinations To: [EMAIL PROTECTED] Date: Sunday, August 31, 2008, 8:38 AM Yua

Re: [R] give all combinations

2008-08-31 Thread Yuan Jian
"a","b","c") v v should be aa, ab, ac, bc    --- On Sun, 8/31/08, Lucien Lemmens <[EMAIL PROTECTED]> wrote: From: Lucien Lemmens <[EMAIL PROTECTED]> Subject: Re: [R] give all combinations To: [EMAIL PROTECTED] Date: Sunday, August 31, 2008, 8:38 AM Yuan Ji

Re: [R] give all combinations

2008-08-31 Thread Yuan Jian
t;a","b","c") v v should be aa, ab, ac, bc    --- On Sun, 8/31/08, Lucien Lemmens <[EMAIL PROTECTED]> wrote: From: Lucien Lemmens <[EMAIL PROTECTED]> Subject: Re: [R] give all combinations To: [EMAIL PROTECTED] Date: Sunday, August 31, 2008, 8:38 AM Yuan Ji

Re: [R] give all combinations

2008-08-31 Thread Yuan Jian
;-c("a","b","c") v v should be aa, ab, ac, bc    --- On Sun, 8/31/08, Lucien Lemmens <[EMAIL PROTECTED]> wrote: From: Lucien Lemmens <[EMAIL PROTECTED]> Subject: Re: [R] give all combinations To: [EMAIL PROTECTED] Date: Sunday, August 31, 2008, 8:38 AM Yua

Re: [R] give all combinations

2008-08-31 Thread Yuan Jian
hould be aa, ab, ac, bc    --- On Sun, 8/31/08, Lucien Lemmens <[EMAIL PROTECTED]> wrote: From: Lucien Lemmens <[EMAIL PROTECTED]> Subject: Re: [R] give all combinations To: [EMAIL PROTECTED] Date: Sunday, August 31, 2008, 8:38 AM Yuan Jian yahoo.com> writes: > > Hello, &g

Re: [R] give all combinations

2008-08-31 Thread Yuan Jian
or(i in 1:3){     for (j in i+1:3){     v.v<-c(v.v,paste(v[i],v[j]))     } }   is there simpler way to do? thanks Yu --- On Sun, 8/31/08, Lucien Lemmens <[EMAIL PROTECTED]> wrote: From: Lucien Lemmens <[EMAIL PROTECTED]> Subject: Re: [R] give all combinations To: [EMAIL PROTECT

[R] programming

2008-09-01 Thread Yuan Jian
Hi,   I am looking for R editor. does anyone know good editor? which tells you syntax error and it has function to beautify format (insert TAB etc.).   Yu   [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https:

[R] by funtion

2010-04-28 Thread Yuan Jian
Hello, I have a data.frame: name    col1    col2    col3    col4 AA    23    54    0.999    0.78 BB    123    5    1    0.99 AA    203    98    0.79    0.99 I want to get mean value data.frame in terms of name: name    col1    col2    col3    col4 AA    113.  76.   0.8945   0.8850 BB  

Re: [R] by funtion

2010-04-29 Thread Yuan Jian
999  0.78  87   6   BB    123   5   1.000   0.99  98   7 could give advice? --- On Thu, 29/4/10, Tengfei Yin wrote: From: Tengfei Yin Subject: Re: [R] by funtion To: "Petr PIKAL" Cc: "Yuan Jian" , r-help@r-project.org Received: Thursday, 29 April, 2010, 6:44 AM Hi,  Tha

[R] list matching

2010-06-14 Thread Yuan Jian
Hello,   I could not find a clear solution for the follow question. please allow me to ask. thanks   mynames=cbind(c('a','b'),c(11,22)) lst=list(a=c(1,2), b=5) now I try to combine mynames and lst: a  1  11   a  2  11 b  5  22   thanks jian   [[alternative HTML version deleted]]

[R] list operation

2010-06-23 Thread Yuan Jian
Hi,   it seems a simple problem, but I can not find a clear way. I have a list: lst=list(m=c('a','b','c'),n=c('c','a'),l=c('a','bc')) > lst $m [1] "a" "b" "c" $n [1] "c" "a" $l [1] "a"  "bc" how can I get list elements that include a given subset? for example, for given subset {'a','c'}, the answ

[R] class

2010-07-22 Thread Yuan Jian
Hello,   ###  I created two classes "A" and "B". "A" is the superclass of "B".   setClass("A", representation(s1="numeric"),prototype=prototype(s1=8)) setClass("B",contains="A",representation(s2="character"),prototype=list(s2="hi")) myA=new("A") myB=new("B")     I created functions for "A" and

[R] NULL

2010-07-25 Thread Yuan Jian
hi, I have a simple problem. how can I test whether a variable is NULL? a = NULL if (a == NULL){ ... } it seems not work thanks YU [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mail

[R] for loop

2010-09-11 Thread Yuan Jian
Hello, I have a simple question: I want to list numbers 1:k, but if k <1, I hope nothing listed. how should we do? k=2 for (i in 1:k)  print(i) [1] 1    # <-correct [1] 2 k=0 for (i in 1:k) print(i) [1] 1  #< wrong [1] 0   thanks jian [[alternative HTML version delete

[R] merge verctor and matrix

2010-09-22 Thread Yuan Jian
hi, can anyone tell me how to merge a vector and a matrix? > v=c(1,4,2) > names(v)=c("e","r","t") > m=matrix(c("r","t","r","s","e",5,6,7,8,9),nr=5) > colnames(m)=c("c1","c2") I want to do like merge(v, m, by.x="names",by.y="c1") I got error Error in fix.by(by.x, x) : 'by' must specify valid column(

[R] colname refered by a variable

2010-12-02 Thread Yuan Jian
Hello,   I tried to use a variable to refer colname, but I got error, could anyone give me advice?   >df=data.frame(cbind(AB=1:3,AC=3:5)) > df$AC [1] 3 4 5 > df$paste("A","C",sep="") Error: attempt to apply non-function thanks Jian   [[alternative HTML version deleted]]

[R] plot: skip a range of axis

2011-01-11 Thread Yuan Jian
Hi, I am using plot to show scatter points in 2_D. in my data, there is no data between -1 and +1 in x-axis. I want to skip this region, i.e. x axis becomes [-Inf:-1, 1:Inf]. can any one tell me how to do? YU [[alternative HTML version deleted]]

Re: [R] plot: skip a range of axis

2011-01-12 Thread Yuan Jian
thanks Jim, I found gap.plot seperates x axis or y axis into two boxes. do you know any plot tool that can skip a range in x-axis or y-axis without lines?   regards YU --- On Wed, 12/1/11, Jim Lemon wrote: From: Jim Lemon Subject: Re: [R] plot: skip a range of axis To: "Yuan Jian&qu

[R] how to get p-value from ave

2010-05-10 Thread Yuan Jian
Hi there, I checked google for aov. usually one uses summary to see whether the p-value is small. but I want to put aov in my script. how can I get the p-value, (0.1115, 0.6665, 0.6665 in the following example)? thanks YU > datafilename="http://personality-project.org/r/datasets/R.appendix2.

[R] create a data.frame for aov

2010-05-11 Thread Yuan Jian
Hi R-experts, I try to find a way to transfer a matrix to a data.frame that is used as input of aov. can you give me advice for that? >mdat <- matrix(c(1,2,3, 11,12,13), nrow = 2, ncol=3, byrow=TRUE, dimnames = >list(c("row1", "row2"), c("Col1", "Col2", "Col3"))) >mdat Col1 Col2 Col3 row1 

[R] intersect

2010-05-11 Thread Yuan Jian
Hi there, how can I test every element in a vector whether appears in another vector? such as a<-c("aa", "bb", "ff", "cc") b <-c("oo","jj","bb","cc") somefunction(a,b) gives [False, True

[R] merge for data.frame and matrix

2010-05-13 Thread Yuan Jian
ist(c("aa","kk"),c("col1","col2"))) > m    col1 col2 aa    3   56 kk    8    9 the result is expected as col1.x col2.x col1.y col2.y kk   6    8    9 kk   3    8    9 Yuan Jian [[alternative HTML version dele

[R] sort a data.frame

2010-05-20 Thread Yuan Jian
Hello,   I have a dataframe: dd <- data.frame(b = c("chr2", "chr1", "chr15", "chr13"),     x = c("A", "D", "A", "C"), y = c(8, 3, 9, 9),     z = c(1, 1, 1, 2))   >dd   b x y z 1  chr2 A 8 1 2  chr1 D 3 1 3 chr15 A 9 1 4 chr13 C 9 2 Now I want to sort them according column "b", but onl

Re: [R] sort a data.frame

2010-05-20 Thread Yuan Jian
Re: [R] sort a data.frame To: "Yuan Jian" Cc: r-help@r-project.org Received: Thursday, 20 May, 2010, 1:31 PM Hi Yuan, Try  dd[order(as.numeric(gsub("[^0-9]", "", dd$b))), ] HTH,Jorge On Thu, May 20, 2010 at 8:28 AM, Yuan Jian <> wrote: Hello,   I have

[R] vaiable in lm

2010-05-21 Thread Yuan Jian
Hi, if I know the colnames x and y in the following example, I can easily to do lm. tmp <- data.frame(x=c(1,1.2),y=c(1,2)) lm(y ~ x, data=tmp) when the colnames are variable, what should I do? for example colnames(tmp)[1] <- paste("aa",1,sep="_") lm(y ~ paste("aa",1,sep="_"), data = tmp) it gives

[R] charactor matrix convert to numeric matrix

2010-06-02 Thread Yuan Jian
Hello R experts, can you tell me a simple way to convert a charactor matrix to numeric matrix? if I use as.numeric, the matrix is converted to a vector. a<-cbind(c("23","54","65"),c("1","2","3")) a [,1] [,2] [1,] "23" "1" [2,] "54" "2" [3,] "65" "3"  as.numeric(a) [1] 23 54 65  1  2  3 t

[R] average two sets of columns

2010-06-07 Thread Yuan Jian
Hi R experts. how can I average two sets of columns? dd <- data.frame(b = c("chr2", "chr1", "chrY", "chr13", "chrX"),     w=11:15, x = 1:5, y = c(8, 3, 9, 9,7),    z = c(1, 1, 1, 2, 8)) expected result for mean(w,x) and mean(y,z) is 1  chr2 6  4.5 2  chr1 7  2 3  chrY 8  5 4 chr13 9  5.5

[R] SAS file

2016-08-05 Thread Yuan Jian via R-help
Hello,I have a SAS formatted file as attached, when I use lookup.xport i got error below> lookup.xport("patient.ssd01")Error in lookup.xport.inner(file) :   unable to open file: 'No such file or directory' can anyone please help me to figure it out? thanksyuan ___

[R] lm

2016-02-20 Thread Yuan Jian via R-help
Hello,I used l  to draw a figure, but I got different result (26 vs 301) when I input the same parameters. > length(predict(lm(A$Counts ~ AT),list(ATE=timevalues))) [1] 26 > length(predict(lm(A$Counts ~ ATE),list(ATE=timevalues))) [1] 301 all variables are initialized as below: >A <- structure(l