-2

I am new in R and I had made some graphs with small dataset. Now I want to plot (histogram and correlation) in a dataset with 9 variables and 107 observations.

its about deaths per 100.000 people caused by lung cancer. I have five columns with numbers of deaths per 100.000, one for a range of age(0-14 years, 15-44, 45-54, 55-64, 65+) In the rows there are the states of the country. I have done this with no success:

hist(PULMON.R$X0.14.años, PULMON.R$X15.44.años, PULMON.R$X45.54.años, PULMON.R$X55.64.años, PULMON.R$X65.Y.MAS.años)
Error in hist.default(PULMON.R$X0.14.años, PULMON.R$X15.44.años, PULMON.R$X45.54.años,  : 
  'probability' is an alias for '!freq', however they differ.

And I get a strange graphic with several numbers in axis X doing this:

barplot(PULMON.R$X0.14.años, PULMON.R$X15.44.años, PULMON.R$X45.54.años, PULMON.R$X55.64.años, PULMON.R$X65.Y.MAS.años)

And for the correlation I get nothing. I want to see if there is a relation between age (getting older) with more death cases. I have done this:

cor(PULMON.R$X0.14.años, PULMON.R$X15.44.años, PULMON.R$X45.54.años, PULMON.R$X55.64.años, PULMON.R$X65.Y.MAS.años)
Error in cor(PULMON.R$X0.14.años, PULMON.R$X15.44.años, PULMON.R$X45.54.años,  : 
  unused argument (PULMON.R$X65.Y.MAS.años)

My dataset is PULMON.R Pulmon means lung in Spanish.

Thomas
  • 43,637
  • 12
  • 109
  • 140
user1985481
  • 17
  • 1
  • 4
  • add a reproducible example (http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so SO can help you – MLavoie Jan 19 '16 at 22:17
  • It will be easier to show you how to fix these problems if you provide a sample of your data. Please add to your question the output of `dput(PULMON.R[1:10,])`. – eipi10 Jan 19 '16 at 22:18
  • I think you want `cor(PULMON.R[,c("X0.14.años","X15.44.años","X45.54.años",etc)]) ` – fishtank Jan 19 '16 at 22:19

1 Answers1

1

That's not how any of these functions work. You can't simply pass a large number of vectors to each. Take a look at the help files for each function (? hist, ? barplot, ? cor) to see what is possible.

  • cor() expects a matrix as its first argument
  • hist() expects a single vector as its first argument
  • barplot() expects a vector of heights (not a raw vector) as its first argument

So your cor() line can be:

cor(cbind(PULMON.R$X0.14.años, PULMON.R$X15.44.años, PULMON.R$X45.54.años, PULMON.R$X55.64.años, PULMON.R$X65.Y.MAS.años))

But the others will need to be separate plots, which you can create in a loop:

layout(matrix(1:5, nrow = 1))
lapply(PULMON.R[, c("X0.14.años", "X15.44.años", "X45.54.años", "X55.64.años", "X65.Y.MAS.años")], hist)
Thomas
  • 43,637
  • 12
  • 109
  • 140