2

I am trying to subset my dataset as follows

df[df$Age > 19,]

I am seeing an error , Error: x and labels must be same type

I am not sure I understand this, any suggestions are much appreciated.

=================

dput(df$Age)

c(20, 11, 10, 15, 6, 23, 45, 30, 18, 11, 15, 20, 7, 18, 19, 30, 
40, 16, 14, 33, 12, 22, 12, 5, NA, 18, 30, 26, 25, 27, 12, 27, 
13, 15, 32, 19, NA, 18, 13, 30, 10, 16, 47, 24, 64, 21, 9, 30, 
12, 33, 16, 20, 14, 10, 19, 18, 20, 18, 10, 15, 55, 18, 50, 14, 
35, 18, 21, 17, 14, 9, 25, 17, 10, 16, 12, 30, 38, 10, 27, 20, 
27, 16, 30, 11, 5, 20, 30, 12, 24, 11, 7, 26, 48, 25, 20, 18, 
27, 18, 28, 15, 17, 46, 30, 20, 20, 14, 35, 31, 10, 26, 13, NA, 
15, 3, 30, 33, 15, 43, 19, 40, 8, 16, 8, 3, 37, 40, 58, 18, 12, 
19, 14, 24, 34, 30, 23, 28, 47, 29, 21, 35, 23, 47, 11, 30, 16, 
25, 30, 30, 8, 18, 20, 12, 8, 18, 30, 6, 54, 60, 18, 27, 42, 
6, 42, 13, 21, 15, 17, 10, 33, 15, 16, 36, 16, 52, 4, 30, 28, 
30, 14, 13, 14, NA, 15, 20, 20, 24, 27, 23, 10, 13, 22, 30, 45, 
10, 23, 14, 27, 19, 12, 25, 10, 10, 14, 16, 16, 19, 18, 12, 65, 
18, 35, 20, 31, NA, 21, 40, 8, 13, 25, 8, 13, 15, 19, 25, 10, 
9, 24, 8, 25, 30, 38, 35, 20, 12, 15, 25, 27, 39, 8, 10, NA, 
12, 50, 16, 14, 22, 12, 20, 44, 13, 8, 43, 48, 13, 21, 20, 42, 
11, 20, 35, 53, 22, 17, 5, NA, 14, 10, 21, 33, 21, 69, 24, 15, 
12, 8, 28, 11, 32, 25, 26, 21, 36, 12, 24, 20, 23, 14, 30, 50, 
26, NA, 30, 22, 44, 22, 14, 30, 28, 10, 16, 32, 35, 40, 16, 40, 
33, 23, 25, 10, 17, 10, 14, 22, 14, 25, 20, 39, 24, 52, 16, 34, 
26, 23, 11, 12, 70, 59, 12, 38, 22, 13, 40, 57, 30, 7, 21, 20, 
30, 12, 13, 5, 19, 35, 56, 17, 40, 48, 19, 8, 30, 21, 5, 40, 
16, 22, 20, 17, 16, 30, 18, 13, 17, NA, 40, 9, 24, 26, 20, 22, 
17, 44, 45, 18, 26, 50, 10, 21, 15, NA, 20, 12, 16, 54, 15, 16, 
33, 22, 26, 60, 35, 11, 30, 16, 48, 16, 16, 16, 10, 14, 15, 23, 
17, 18, NA, 49, 12, 7, 18, 24, 17, 14, 30, 13, 6, 51, 36, 16, 
10, 43, 34, 15, 12, 15, 15, 17, 40, 58, 15, 33, 16, 48, 25, 15, 
16, 5, NA, 40, 34, 10, 30, 30, 30, 15, 15, 12, 5, 10, 20, 18, 
20, 16, 20, 26, 12, 14, 14, 20, 12, 30, 30, 29, 22, 19, 26, 11, 
23, 40, 30, 16, 50, 20, 25, 29, 40, 44, 20, 40, 8, 16, 15, 38, 
11, 27, 63, 16, NA, 47, 65, 21, 29, 30, 16, 21, 25, 16, 23, 5, 
17, 22, 12, 14, 27, NA, 16, 9, 33, 11, 15, 34, 41, 30, 33, 15, 
25, 40, 25, 12, 12, 17, 14)
Emily Fassbender
  • 413
  • 5
  • 15
  • 1
    I think your `Age` column is not an integer. Can you share the output of `str(df)`? – SmitM Aug 13 '18 at 15:34
  • what is the output of this command: `typeof(df$Age)` your `Age` attribute is probably not a numeric. – f-roche Aug 13 '18 at 15:35
  • @f-roche, it says,typeof(df$Age) is `double` – Emily Fassbender Aug 13 '18 at 15:40
  • @SmitM, it says, `num [1:520] 20 11 10 15 6 23 45 30 18 11 ...` – Emily Fassbender Aug 13 '18 at 15:41
  • 1
    Can you post sample data? Please edit **the question** with the output of `dput(df)`. Or, if it is too big with the output of `dput(head(df, 20))`. – Rui Barradas Aug 13 '18 at 15:42
  • Are you using the [tidyverse](https://github.com/tidyverse/haven/issues/86) to read the data in? – Rui Barradas Aug 13 '18 at 15:45
  • @RuiBarradas, I have included the output from dput function. No I am not using tidyverse, just `readRDS` – Emily Fassbender Aug 13 '18 at 15:53
  • 1) Can you try `df[df$Age > 19, , drop = FALSE]`? 2) Maybe there is something in you R session saved from a previous one, can you see if you have a file named `.RData` in your working directory? If yes, delete it and restart R. (That is not a file extension, it's the full file name). – Rui Barradas Aug 13 '18 at 16:22
  • 1
    I've run into the same issue before when loading tidyverse after Hmisc - see this post https://stackoverflow.com/questions/49392779/evaluation-error-when-tidyverse-is-loaded-after-hmisc – Mike Aug 13 '18 at 16:23
  • what if you load tidyverse and use filter function: `library(tidyverse)` `df %>% filter(Age>19)` I highly recommend to use it for managing data. – f-roche Aug 14 '18 at 09:28
  • oh and BTW did this error happen since you upgraded packages recently? – f-roche Aug 14 '18 at 09:35

0 Answers0