Re: [R] Create a new vector with filled with mean value of original vector

From: Peter Dalgaard <P.Dalgaard_at_biostat.ku.dk>
Date: Mon, 23 Jun 2008 12:24:28 +0200

Gavin Simpson wrote:
> On Mon, 2008-06-23 at 17:47 +0900, Gundala Viswanath wrote:
>

>> Hi,
>>
>> Given this vector:
>>
>>     
>>> x <- c(30.9, 60.1  , 70.0 ,  73.0 ,  75.0 ,  83.9 ,  93.1 ,  97.6 ,  98.8 , 113.9)
>>>       
>>  [1]  30.9  60.1  70.0  73.0  75.0  83.9  93.1  97.6  98.8 113.9
>>
>>     
>>> mean.x <- mean(x)
>>>       
>> [1] 79.63
>>
>> I wish to:
>>
>> 1. Create a new vector (nx) with the same size as "x"
>> 2. Fill "nx" with the mean value
>>     
>

>
>> rep(mean(x), length(x))
>>     

> [1] 79.63 79.63 79.63 79.63 79.63 79.63 79.63 79.63 79.63 79.63
>

Or even

> ave(x)

 [1] 79.63 79.63 79.63 79.63 79.63 79.63 79.63 79.63 79.63 79.63

> You have asked several introductory R questions today, suggesting you
> are a new useR. This basic material is covered in the documentation
> provided with R or available from the R Website. I suggest you start
> with 'An Introduction to R':

>

> http://cran.r-project.org/manuals.html
>

> The first 30 or so pages of which describe the major pieces of basic R
> usage. Far more efficient to consult the docs than to wait for a
> response from the list, even if the response time on R-Help is
> generally /very/ quick!
>
Well, actually, the list is often faster. The problem is that if everyone asks the list instead of looking things up, we'll get flooded, so people asking too many questions tend to experience a sharp decline in helpful replies.
-- 
   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard_at_biostat.ku.dk)              FAX: (+45) 35327907

______________________________________________
R-help_at_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 commented, minimal, self-contained, reproducible code.
Received on Mon 23 Jun 2008 - 10:30:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 23 Jun 2008 - 11:30:49 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive