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

From: Thomas Lumley <tlumley_at_u.washington.edu>
Date: Wed 01 Jun 2005 - 09:40:23 EST

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

numeric(0) is a zero-length vector of floating point numbers, so your first example takes no floating point numbers and adds 5 to each one. The result is still no floating point numbers.

numeric(1) is a vector containing a single 0, so the second example takes 0 and adds 5, to give a vector containing a single 5.

         -thomas



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 09:47:40 2005

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