quit() - end the current R session. q() works too.
x<-c(1,2,4,5) - Create a vector containing the numbers given.
mean(x) - calculate the mean of those numbers
barplot(x) - chart the values of x. Starting to get interesting.
abline(h=mean(x)) - add an a-b line to the previous plot. The line is horizontal with a height of mean(x). Useful for adding 'targets' to a chart.
help(package=ggplot2) - an extended use of the help function. Profice a value to the package parameter.
data() - list the data sources available in the current session.
AirPassengers - One of the included datasets. Entering it like this just prints it.
plot(AirPassengers) - produce a plot of the number of air passengers over time. This is what it looks like. I am a long way from being able to quantify that seasonal variation, but it is an interesting thing to look at when I know how.
![]() |
| AirPassengers plot |
women - dataset of womens height vs weight.
plot(women$height, women$weight) - plots a scatter of womens weight vs weight, but unnecessary as the data is in columns. plot(women) would do the same job.
mdeaths - this one is the monthly deaths from lung disease in the UK.
Note that you can use tab to autocomplete a lot of stuff in R. For example datasets. There are a large number of them and tab allows you to pick out the ones you need nice and quick.
Note: Typing help(dataset) gives you information on the dataset, including sources.
uspop - population of the United States.
There are a lot of datasets that some with R. They are in nice formats unlike most of the stuff I have tried to play with so far. Hopefully with increased skill I will be able to press the data into the format I need to plot and manipulate it.

No comments:
Post a Comment