# [R] Various newbie questions

Rau, Roland Rau at demogr.mpg.de
Wed Feb 4 14:59:48 CET 2004

```Hi,

> -----Original Message-----
> From:	Philippe de Rochambeau [SMTP:philippe at wwphi.net]
> Sent:	Wednesday, February 04, 2004 12:33 PM
> To:	r-help at stat.math.ethz.ch
> Subject:	[R] Various newbie questions
>
> year snow.cover
> 1970 6.5
> 1971 12.0
> 1972 14.9
> 1973 10.0
> 1974 10.7
> 1975 7.9
> ...
>
> mydata=data.frame(year=c(1970,...),snow.cover=c(6.5,...))
>
> 2) How to you retrieve say, snow.cover's second data item? mydata[1][2]
> does not work, neither does mydata[1,2].
>
year <- 1970:1975
snow.cover <- c(6.5,12,14.9,10,10.7,7.9)
mydata <- data.frame(cbind(year,snow.cover))

# retrieving 2nd column:
mydata[,2]

# retrieving 3rd row:
mydata[3,]

# snow.cover's second data-item:
mydata[2,2]
# or:
mydata\$snow.cover[2]

> In a French statistics book, the author provides the following data:
>
> Group A	Number: 35	Mean:27
> Group B  Number: 42  Mean:24
>
> and asks: "what is the mean of the group constituted by the reunion of
> the two groups?"
>
> The answer is of course (27 x 35) + (24 x 42) / 77
>
> 3) Is there a way to compute this mean in R (apart from doing the above
> operation, of course) if you have two sets of data?
>
numbers <- c(35,42)
arithmeans <- c(27,24)

weighted.mean(arithmeans,numbers)

Just a general remark: the first thing you should do (as is written
For example, you could use
?vector
?data.frame
If you don't know actually what you are looking for, you can also
enter a search string and, optionally, the package.
In the case of question 3, you could have written:
help.search("mean", package="base")
and R would have returned several commands - among them also
"weighted.mean"

Best,
Roland

+++++
This mail has been sent through the MPI for Demographic Research.  Should you receive a mail that is apparently from a MPI user without this text displayed, then the address has most likely been faked.   If you are uncertain about the validity of this message, please check the mail header or ask your system administrator for assistance.

```