Jacob Liljehult
Klinisk sygeplejespecialist
cand.scient.san, Ph.d.
Neurologisk afdeling
Nordsjællands Hospital
Hvis man ønsker at tælle hvor mange der er i hver gruppe kan man bruge funktionen table() eller
summary() (de giver samme output):
table(strokedata$diagnosis)
table(strokedata$inhospmors)
| ICH | IS |
|---|---|
| 110 | 921 |
| Alive | Dead |
| 971 | 60 |
Man kan også lave en 2 x 2 table:
with(strokedata, table(diagnosis, inhospmors))
| inhospmors | ||
|---|---|---|
| diagnosis | Alive | Dead |
| ICH | 88 | 22 |
| IS | 883 | 38 |
For at få procenter bruges funktionen prop.table()
with(strokedata, prop.table(table(diagnosis, inhospmors)))
| inhospmors | ||
|---|---|---|
| diagnosis | Alive | Dead |
| ICH | 0.08535403 | 0.02133851 |
| IS | 0.85645005 | 0.03685742 |
with(strokedata, prop.table(table(diagnosis, inhospmors) ,1)) # Procent for rækker
with(strokedata, prop.table(table(diagnosis, inhospmors) ,2)) # Procent for koloner
| inhospmors | ||
|---|---|---|
| diagnosis | Alive | Dead |
| ICH | 0.8000000 | 0.2000000 |
| IS | 0.9587405 | 0.0412595 |
| inhospmors | ||
|---|---|---|
| diagnosis | Alive | Dead |
| ICH | 0.09062822 | 0.36666667 |
| IS | 0.90937178 | 0.63333333 |