-1

I have this table:

Table smoker

Now I would like to create a cross table only for agecat younger, so it would look something like this:

/ alive / dead

1 / 372 / 46

0 / 393 / 25

I want to work with subsets to obtain the right data from the original table but I don't really know where to start, can someone help me out?

Community
  • 1
  • 1
Stan
  • 95
  • 1
  • 1
  • 10
  • Please use `dput()` to present your data! image files are useless. – jogo Mar 19 '17 at 13:21
  • I'm sorry, I'm new to R and also quite new to this website. I have no clue what dput() will do and how to use it. Also I don't see why this image is useless; I only posted it to clarify my question. – Stan Mar 19 '17 at 13:25
  • I looked at the possible duplicate but it's not the same. I want to work with subsets which they don't use there. – Stan Mar 19 '17 at 13:29
  • Please, [edit] your question and provide a [mcve]. And, have a look at [How to make a great R reproducible example?](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), please, There you will find an explanation of `dput()`. Thank you. – Uwe Mar 19 '17 at 13:39
  • @Stan Please put the result of `dput(yourDataframe)` in your question. i.e. edit your question: http://stackoverflow.com/posts/42886977/edit – jogo Mar 19 '17 at 14:51

1 Answers1

1

try:

SmokersAlive <- subset(df, Smoker == 1)            #table showing only the smokers
SmokersAlive <- sum(subset(df, Smoker == 1)$Alive) #sum of col. "Alive" from table above

here the code you need:

SmokersAlive <- sum(subset(df, Smoker == 1)$Dead)

SmokersDead     <- 1 #sum(subset....) should stand here
NonSmokersAlive <- 1 #...
NonSmokersDead  <- 1

Overview <- data.frame(matrix(c(SmokersAlive, SmokersDead, NonSmokersAlive, NonSmokersDead), ncol = 2, byrow = TRUE))

colnames(Overview) <- c("alive","dead")
rownames(Overview) <- c("0","1")

Overview
DataAdventurer
  • 300
  • 1
  • 3
  • 10