I think I could be more helpful if I could understand better what you're ultimately trying to do. I have guesses below but I'm not sure.
To review:
You used the table function and it showed you the counts for each of the existing values in your data. For example, you have 1 value of 1.8, 2 of 1.9, 2 of 2, etc. You got an error in the last step because the table function requires that each of the objects you feed it (if more than one) have the same number of elements. The first term included the 183 different GAG values that got counted, but your 2nd term did not have 183 elements.
Here I make some fake data that is meant to behave like yours
library(tidyverse, quietly = TRUE)
# 1. Let's make some fake data with 100 data points [edit: typo]
n <- 100
GAGurine_fake <-
tibble(
# First column will be Age, randomly populated between 0 and 0.5, rounded to the hundredth
Age = round(runif(n, 0, 0.5), digits = 2),
# Second column will be GAG, randomly populated between 1 and 30, rounded to the tenth
GAG = round(runif(n, 1, 30), digits = 1)
)
Here I try what you tried and see that it seems structurally the same
# 2. Let's try what you tried
GAGurine.GAG <- GAGurine_fake$GAG
typeof(GAGurine.GAG)
#> [1] "double"
GAGurine.GAG.absH <- table (GAGurine.GAG)
typeof(GAGurine.GAG.absH)
#> [1] "integer"
head(GAGurine.GAG.absH)
#> GAGurine.GAG
#> 1.3 1.9 2.3 2.4 3 3.5
#> 1 1 1 1 2 2
I suspect you're trying to do one of two things:
- Get counts of the GAG variable in wider bins, i.e. how many results have a GAG value between 0 and 5, how many are in the range 5-10, etc.
- Get counts of counts, i.e. how many values showed up 0-5 times, how many values showed up 5-10 times, etc.
One strategy for the 1st question would be to add a column showing which group you want each GAG value to go into. For instance,
GAGurine_fake$GAG_grp <- cut(GAGurine_fake$GAG, breaks = 5*0:12)
table(GAGurine_fake$GAG_grp)
#>
#> (0,5] (5,10] (10,15] (15,20] (20,25] (25,30] (30,35] (35,40] (40,45]
#> 13 20 12 20 20 15 0 0 0
#> (45,50] (50,55] (55,60]
#> 0 0 0
One strategy for the 2nd question would be to use dplyr
's group
_by and summarize
functions, first replicate the counting you did with table
, then again to count those counts:
GAGurine_counts <-
GAGurine_fake %>%
group_by(GAG) %>%
summarize(count = n())
GAGurine_count_counts <-
GAGurine_counts %>%
group_by(count) %>%
summarize(count_the_counts = n())
GAGurine_count_counts
#> # A tibble: 3 x 2
#> count count_the_counts
#> <int> <int>
#> 1 1 64
#> 2 2 15
#> 3 3 2