[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 B   f1=function(x,...)

[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

[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

[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(s)   thanks jian  

[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
? --- On Thu, 29/4/10, Tengfei Yin yinteng...@gmail.com wrote: From: Tengfei Yin yinteng...@gmail.com Subject: Re: [R] by funtion To: Petr PIKAL petr.pi...@precheza.cz Cc: Yuan Jian jayuan2...@yahoo.com, r-help@r-project.org Received: Thursday, 29 April, 2010, 6:44 AM Hi,  Thanks, actually I

[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

[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    1    2   

[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, False, True] thanks yuan jian [[alternative HTML version deleted

[R] merge for data.frame and matrix

2010-05-13 Thread Yuan Jian
    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 deleted]] __ R-help@r-project.org mailing list https

[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 only its number is

Re: [R] sort a data.frame

2010-05-20 Thread Yuan Jian
jorgeivanve...@gmail.com wrote: From: Jorge Ivan Velez jorgeivanve...@gmail.com Subject: Re: [R] sort a data.frame To: Yuan Jian jayuan2...@yahoo.com 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

[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 me

[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 thanks Jian

[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 5  chrX

[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

[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 answer should be 

[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) d   

Re: [R] cbind in data.frame

2008-08-25 Thread Yuan Jian
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. in the script below, column

[R] add to vector without duplicatation

2008-08-28 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

[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) NULL attributes(kk)

[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] 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
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 jayuan2008 at yahoo.com writes: Hello,   is there a simple way to give all combinations for a given vector:   v-c(a,b,c

Re: [R] give all combinations

2008-08-31 Thread Yuan Jian
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 jayuan2008 at yahoo.com writes: Hello,   is there a simple way to give all combinations for a given vector:   v-c(a,b,c

Re: [R] give all combinations

2008-08-31 Thread Yuan Jian
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 jayuan2008 at yahoo.com writes: Hello,   is there a simple way to give all combinations for a given vector:   v-c(a,b,c

Re: [R] give all combinations

2008-08-31 Thread Yuan Jian
   --- 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 jayuan2008 at yahoo.com writes: Hello,   is there a simple way to give all

Re: [R] give all combinations

2008-08-31 Thread Yuan Jian
   --- 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 jayuan2008 at yahoo.com writes: Hello,   is there a simple way to give all

Re: [R] give all combinations

2008-08-31 Thread Yuan Jian
   --- 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 jayuan2008 at yahoo.com writes: Hello,   is there a simple way to give all combinations

Re: [R] give all combinations

2008-08-31 Thread Yuan Jian
   --- 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 jayuan2008 at yahoo.com writes: Hello,   is there a simple way to give all

Re: [R] give all combinations

2008-08-31 Thread Yuan Jian
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 jayuan2008 at yahoo.com writes: Hello,   is there a simple way to give all combinations for a given vector:   v-c(a,b,c

Re: [R] give all combinations

2008-08-31 Thread Yuan Jian
){     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 PROTECTED] Date: Sunday, August 31, 2008, 8:38 AM Yuan Jian

[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

[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
a range of axis To: Yuan Jian jayuan2...@yahoo.com Cc: r-help@r-project.org Received: Wednesday, 12 January, 2011, 10:26 AM On 01/12/2011 03:46 PM, Yuan Jian wrote: 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

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

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

[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