0

I am new (very new) to R.

I am working on demographic data frame (POP) of 4 variables : population (int), age(numeric), gender (factor), region (factor) and would like to summarise age by region.

I found the describeBy function but the results in each group are those of the global population.

describeBy(POP$age,group=POP$region)

There must be a stupid error somewhere. Thank you for your help

Trying some code description (but not sure how it will appear) GLobal description:

summary(POP$age)  
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   0.00   13.75   27.50   27.50   41.25   55.00 

Group description:

> describeBy(POP$age,group=POP$region)
group: REGION1
   vars   n mean    sd median trimmed   mad min max range skew kurtosis   se
X1    1 112 27.5 16.24   27.5    27.5 20.76   0  55    55    0    -1.23 1.53
-------------------------------------------------------------------------- 
group: REGION2
   vars   n mean    sd median trimmed   mad min max range skew kurtosis   se
X1    1 112 27.5 16.24   27.5    27.5 20.76   0  55    55    0    -1.23 1.53
-------------------------------------------------------------------------- 
group: REGION3
   vars   n mean    sd median trimmed   mad min max range skew kurtosis   se
X1    1 112 27.5 16.24   27.5    27.5 20.76   0  55    55    0    -1.23 1.53
-------------------------------------------------------------------------- 
etc...
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
SBG
  • 11
  • 2
  • 1
    Welcome to SO ! please provide a reproducible example of your data by following explanation of this link: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – dc37 Feb 01 '20 at 22:40
  • So trying to produce a sample of my data and code, it worked! Then I compared original dataset and sample to find out that in the original dataset some values for population were =0; I filtered and it worked. – SBG Feb 01 '20 at 23:27
  • Glad you figure it out yourself ;) – dc37 Feb 01 '20 at 23:33

1 Answers1

1

I think I found the answer : some rows had population=0; Filtering these observations, the describeBy function worked.

SBG
  • 11
  • 2