RE: [R] FW: why is it numeric(0)?

From: luan_sheng <luan_sheng_at_yahoo.com.cn>
Date: Wed 01 Jun 2005 - 08:40:32 EST


 yea, I have read the help. But some one tell me that i f you want use a vector that you don't know it's length, you should use xx=numric(0) , is it not right? If it isn't right, how can I do? thanks

-----Original Message-----
From: Douglas Grove [mailto:dgrove@fhcrc.org] Sent: Wednesday, June 01, 2005 6:27 AM
To: luan_sheng
Subject: Re: [R] FW: why is it numeric(0)?

Have you read the help page for numeric (?numeric) to understand what it does? You should really look at help pages prior to posting.

numeric(x) returns a numeric vector of length x, with all entries initialized to zero

so numeric(1) returns 0,
numeric(2) returns c(0,0)
etc.

numeric(0) returns a numeric vector of *length 0*, so when you add anything to it you get the same result (it's basically a numeric NULL)

On Wed, 1 Jun 2005, luan_sheng wrote:

> hello,everyone. I have one question:
>
> example 1
> > x=numeric(0)
> > y=5
> > print(x+y)
> numeric(0)
>
> example 2
> > x=numeric(1)
> > y=5
> > print(x+y)
> [1] 5
>
> why the print(x+y) is numeric(0) at the first example, but the result
> is 0 at the second example?
>
>
> __________________________________________________
>
> 雅虎免费G邮箱-中国第一绝无垃圾邮件骚扰超大邮箱
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>


雅虎免费G邮箱-中国第一绝无垃圾邮件骚扰超大邮箱



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jun 01 08:44:58 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:17 EST