0

Based on the data below:

  • Why am I getting NA_real_ for min and max? (Is it because of NAs in the data?)
  • How can I fix it?

Code:

a = min(df$var_avg)
b = max(dfvar_avg)

Data:

structure(list(var_avg = c(9.68689607087195, 16.0953818390616, 
18.0998523500943, 16.306521204167, 20.5470387991141, 25.8291772619145, 
NA, 35.4491469116561, 15.4745508982036, 23.2651874333525, 27.0296940365844, 
26.4380977770486, NA, NA, NA, 44.2153555901895, 22.7649495529489, 
21.8389139529161, 16.5958904109589, NA, 20.2380444590272, 31.2964687064228, 
17.729275695185, NA, 20.7692765154622, NA, 22.9591706996965, 
22.5590886719711, 13.4110696415388, 17.8828931178738, 54.9075342465753, 
11.5024239192847, 28.3493150684932, 24.5027889426626, 18.7294807644984, 
NA, 27.3339512755311, 30.8415716512181, 7.99372077762284, 34.7672750389632, 
15.4657534246575, 31.7386432614224, NA, NA, 40.5615618078911, 
42.7718931999016, 34.0499425805922, 29.7624600114839, 20.9327741776721, 
21.377520301862, 30.9937002706915, 17.4719834303995, 25.0541875153802, 
20.8512960380609, 15.970999097695, 24.0005208760561, 22.4758510376507, 
1, 35.0236198835206, 24.0723894676401, 21.4455992125338, 48.8047945205479, 
NA, 18.4590599622672, 23.4576490853909, 41.8587154458207, NA, 
16.9142236075794, 7.0674144860963, 40.7208637519482, 26.3881551964564, 
22.683200721844, 11.8490443769994, 14.36133213026, 18.6056394061193, 
NA, 25.6752891477319, 31.1370314166188, 55.3731236157821, NA, 
39.0734353211385, 29.2722377163481, 26.4280821917808, 25.1306578623575, 
NA, 28.9754244934788, 24.1044664096465, 40.0043433680584, 22.6799524239193, 
36.0803994750226, 41.80525387581, 22.9226273480436, 21.3404355672217, 
NA, 25.3902510048396, 21.5737716348126, 22.9185669756378, 21.2586867361168, 
20.2567221720942, 21.1158969731769)), row.names = c(NA, -100L
), class = c("tbl_df", "tbl", "data.frame"))
Ed_Gravy
  • 1,841
  • 2
  • 11
  • 34
  • 1
    What "fix" are you looking for? Do you want to ignore missing values? Then use `a = min(df$var_avg, na.rm = TRUE); b = max(df$var_avg, na.rm = TRUE)` If you have missing values, then you don't know really know what the max is because the max could be missing. Most R functions will preserved NA values if they are present. – MrFlick Aug 31 '23 at 15:51
  • Thank you for the quick response, yes exactly. – Ed_Gravy Aug 31 '23 at 15:51
  • I see that makes sense MrFlick, thank you for explaining :) – Ed_Gravy Aug 31 '23 at 15:54

0 Answers0