Plotting the mean of data

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Plotting the mean of data

Kare Edvardsen
Hi all!

I've got a datstructure like this:

subject  week  value

1 1 4
2 1 8
3 1 3
4 1 5

1 2 5
2 2 6
3 2 2
4 2 6

1 3 3
2 3 7
3 3 3
4 3 7

I'd like to plot the mean of 'value' against week. Is there a direct way
of doing this or do I have to make a new structure with the calculated
values and then plot it?

All the best!

--
###########################################
Kare Edvardsen <[hidden email]>
Norwegian Institute for Air Research (NILU)
Polarmiljosenteret
NO-9296 Tromso       http://www.nilu.no
Swb. +47 77 75 03 75 Dir. +47 77 75 03 90
Fax. +47 77 75 03 76 Mob. +47 90 74 60 69
###########################################

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Plotting the mean of data

jholtman
Here is one way of doing it:

> x  # your data
   subject week value
1        1    1     4
2        2    1     8
3        3    1     3
4        4    1     5
5        1    2     5
6        2    2     6
7        3    2     2
8        4    2     6
9        1    3     3
10       2    3     7
11       3    3     3
12       4    3     7
> x.mean <- tapply(x$value, x$week, mean) # take the mean by 'week'
> x.mean  # resulting vector
   1    2    3
5.00 4.75 5.00
> # plot using 'names' to get the 'week'
> plot(as.numeric(names(x.mean)), x.mean, xlab='week', ylab='mean',
type='b')
>



On 1/2/06, Kare Edvardsen <[hidden email]> wrote:

>
> Hi all!
>
> I've got a datstructure like this:
>
> subject  week  value
>
> 1       1       4
> 2       1       8
> 3       1       3
> 4       1       5
>
> 1       2       5
> 2       2       6
> 3       2       2
> 4       2       6
>
> 1       3       3
> 2       3       7
> 3       3       3
> 4       3       7
>
> I'd like to plot the mean of 'value' against week. Is there a direct way
> of doing this or do I have to make a new structure with the calculated
> values and then plot it?
>
> All the best!
>
> --
> ###########################################
> Kare Edvardsen <[hidden email]>
> Norwegian Institute for Air Research (NILU)
> Polarmiljosenteret
> NO-9296 Tromso       http://www.nilu.no
> Swb. +47 77 75 03 75 Dir. +47 77 75 03 90
> Fax. +47 77 75 03 76 Mob. +47 90 74 60 69
> ###########################################
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>



--
Jim Holtman
Cincinnati, OH
+1 513 247 0281

What the problem you are trying to solve?

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Plotting the mean of data

Uwe Ligges
In reply to this post by Kare Edvardsen
Kare Edvardsen wrote:

> Hi all!
>
> I've got a datstructure like this:
>
> subject  week  value
>
> 1 1 4
> 2 1 8
> 3 1 3
> 4 1 5
>
> 1 2 5
> 2 2 6
> 3 2 2
> 4 2 6
>
> 1 3 3
> 2 3 7
> 3 3 3
> 4 3 7
>
> I'd like to plot the mean of 'value' against week. Is there a direct way
> of doing this or do I have to make a new structure with the calculated
> values and then plot it?

For your data.frame X, you want, e.g.:

   A <- aggregate(X, list(X$week), mean)
   plot(A$week, A$value)

Uwe Ligges

> All the best!
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html