simple subgroup analysis

I am trying to get simple stat #s for subgroups of data

my answers are coming up as NaN and NA

this is one example:
mean(hw1.1$blame_attribution[hw1.1$pid_root==1], na.rm=TRUE)

when i calc for the whole group, blame_attribution, i am getting the correct numbers

please help

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

ï..pid_root slider_undoc vote2020 income education st_postal sex system_justification blame_attribution restriction
1 1 5 1 8 6 MO 0 3.714286 0.000 1.2
2 1 5 1 9 5 NJ 0 4.428571 0.125 2.0
3 2 20 2 11 5 MA 1 3.000000 0.125 1.8
4 1 50 4 1 1 LA 0 4.285714 0.125 4.0
5 3 11 4 8 4 NC 0 3.857143 0.000 1.8
6 3 20 2 11 3 AZ 0 4.571429 0.000 1.4

#Democrat identifiers
mean(hw1.1$blame_attribution[hw1.1$pid_root==2], na.rm=TRUE)
sd(hw1.1$blame_attribution[hw1.1$pid_root==2], na.rm=TRUE)
median(hw1.1$blame_attribution[hw1.1$pid_root==2], na.rm=TRUE)
IQR(hw1.1$blame_attribution[hw1.1$pid_root==2], na.rm=TRUE)

I can't reproduce your issue with the data you are providing (see example below), please provide a proper reproducible example for your issue as explained in the link I gave you before.

hw1.1 <- data.frame(stringsAsFactors=FALSE,
               pid_root = c(1, 1, 2, 1, 3, 3),
           slider_undoc = c(5, 5, 20, 50, 11, 20),
               vote2020 = c(1, 1, 2, 4, 4, 2),
                 income = c(8, 9, 11, 1, 8, 11),
              education = c(6, 5, 5, 1, 4, 3),
              st_postal = c("MO", "NJ", "MA", "LA", "NC", "AZ"),
                    sex = c(0, 0, 1, 0, 0, 0),
   system_justification = c(3.714286, 4.428571, 3, 4.285714, 3.857143, 4.571429),
      blame_attribution = c(0, 0.125, 0.125, 0.125, 0, 0),
            restriction = c(1.2, 2, 1.8, 4, 1.8, 1.4)
)

mean(hw1.1$blame_attribution[hw1.1$pid_root==2], na.rm=TRUE)
#> [1] 0.125
sd(hw1.1$blame_attribution[hw1.1$pid_root==2], na.rm=TRUE) # Not possible to calculate with just one value
#> [1] NA
median(hw1.1$blame_attribution[hw1.1$pid_root==2], na.rm=TRUE)
#> [1] 0.125
IQR(hw1.1$blame_attribution[hw1.1$pid_root==2], na.rm=TRUE)
#> [1] 0

Created on 2019-10-28 by the reprex package (v0.3.0.9000)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.