[R] Calculation of Age heaping

Avi Gross @v|gro@@ @end|ng |rom ver|zon@net
Sun Aug 8 23:48:12 CEST 2021


It is not too clear to me what you want to do and why that package is the way to do it. Is the package a required part of your assignment? If so, maybe someone else can help you find how to properly install it on your machine, assuming you have permissions to replace the other package it seems to require. You may need to create your own environment. If you are open to other ways, see below.

Are you trying to do something as simple as counting how many people in your data are in various buckets such as each age truncated or rounded to an integer from 0 to 99? If so, you might miss some of my cousins alive at 100 or that died at 103 and 105 recently 😉

Or do you want ages in groups of 10 or so meaning the first of two digits is 0 through 9?

Many such things can be done quite easily without the package if you wish.

As far as I can tell, your code reads in a data.frame from your local file with any number of columns that you do not specify. If it is one, the solution becomes much easier. You then for some reason feel the need to convert it to a matrix. You then do whatever your Whipple does several ways.

Here is an outline of ways you can do this yourself.

First, combine all your data into one or more vectors. You already have that in your data.frame but if all columns are numeric, you can of course do something with a matrix.

Then make sure you remove anything objectionable, such as negative numbers or numbers too large or NA or whatever your logic requires.

If you have a variable ready with N entries to hold the buckets, such as length(0:100) or for even buckets of 5, perhaps length(0:99)/5 you initialize that to all zeroes.

Now take your data, and perhaps transform it into a copy where every age is truncated to an integer or divided by 5 first or whatever you need so it contains a pure integer like 6 or 12. What I mean is if your buckets are 5 wide, and you want 5:9 to map into one bucket, your transform might be as.integer(original/5.0) or one of many variants like that.

You can now simply use one of many methods in R to loop through your values that result and assuming you have a zeroed vector called counter and the current value being looked at is N, you simply increment counter[N] or of N-1 or whatever your logic requires.

Alternately R has many built-in methods (or in other packages) like cut() that might do something similar without as much work.

And just for the heck of it, I tried your download instructions. Unlike your three choices, I was offered 13 choices and as I had no clue what YOU were supposed to download, I aborted.

 1: All                               
2: CRAN packages only                
3: None                              
4: colorspace (2.0-1 -> 2.0-2) [CRAN]
5: isoband    (0.2.4 -> 0.2.5) [CRAN]
6: utf8       (1.2.1 -> 1.2.2) [CRAN]
7: cli        (3.0.0 -> 3.0.1) [CRAN]
8: ggplot2    (3.3.3 -> 3.3.5) [CRAN]
9: pillar     (1.6.1 -> 1.6.2) [CRAN]
10: tibble     (3.1.2 -> 3.1.3) [CRAN]
11: dplyr      (1.0.6 -> 1.0.7) [CRAN]
12: Rcpp       (1.0.6 -> 1.0.7) [CRAN]
13: curl       (4.3.1 -> 4.3.2) [CRAN]
14: cpp11      (0.2.7 -> 0.3.1) [CRAN]

In your case, if you selected All, what exactly did you expect?


-----Original Message-----
From: R-help <r-help-bounces using r-project.org> On Behalf Of Md. Moyazzem Hossain
Sent: Sunday, August 8, 2021 5:25 PM
To: r-help using r-project.org
Subject: [R] Calculation of Age heaping

Dear R-expert,

I hope that you are doing well.

I am interested to calculate the age heaping for each digit (0,1,...,9) based on my data set. However, when I run the R code, I got the following errors. Please help me in this regard.

##########################################
library(remotes)
install_github("timriffe/DemoTools")

###
Downloading GitHub repo timriffe/DemoTools using HEAD These packages have more recent versions available.
It is recommended to update all of them.
Which would you like to update?

 1: All
 2: CRAN packages only
 3: None

Enter one or more numbers, or an empty line to skip updates: 1

*After installing some packages, I got the following error message*

package ‘backports’ successfully unpacked and MD5 sums checked
Error: Failed to install 'DemoTools' from GitHub:
  (converted from warning) cannot remove prior installation of package ‘backports’

I am attaching the R-code and data file along with this email.

Please help me in this regard.

Thanks in advance.
--
Best Regards,
Md. Moyazzem Hossain
Associate Professor
Department of Statistics
Jahangirnagar University
Savar, Dhaka-1342
Bangladesh
Website: http://www.juniv.edu/teachers/hossainmm
Research: *Google Scholar
<https://scholar.google.com/citations?user=-U03XCgAAAAJ&hl=en&oi=ao>*;
*ResearchGate
<https://www.researchgate.net/profile/Md_Hossain107>*; *ORCID iD
<https://orcid.org/0000-0003-3593-6936>*



More information about the R-help mailing list