Trouble specifying names -- is this a quoting problem?

19 views
Skip to first unread message

Stuart Luppescu

unread,
Apr 25, 2018, 6:56:15 PM4/25/18
to manip...@googlegroups.com
Hello manipulators, I'm having problems specifying columns in a data frame by name. The structure of my data frame is like this:
str(by.yrq)
Classes 'tbl_df', 'tbl' and 'data.frame': 5 obs. of  4 variables:
 $ assessmentid    : Factor w/ 6 levels "0","267","291",..: 2 3 4 5 6
 $ 2017Q1          : num  28.6 16.4 17.8 28.7 NA
 $ 2017Q2          : num  28.6 16.4 17.9 28.9 28.3
 $ raw.score.byq.sd: num  1.118 0.407 0.451 1.085 NA

I want to calculate the difference between 2017Q1 and 2017Q2 (the last 2 quarters) and then standardize the difference by dividing by the 4th column. The names of all the quarters are in a vector, yrq.list, and the length of the vector is yrq.num. I calculate the difference and std'ized difference like this:

mutate(difference=yrq.list[yrq.num] - yrq.list[yrq.num-1],
       std.difference=difference / raw.score.byq.sd)

This doesn't work, but I don't know why because R crashes on me with this message:
Process R aborted at Wed Apr 25 18:40:44 2018
terminate called after throwing an instance of 'std::length_error'
  what():  basic_string::_M_create
This has been happening a lot to me recently. All I have to do is misspell a variable name and I get Process R aborted. (I know these are all spelled right, though.) Do I need to quote those column names somehow? Also, any idea why I get these crashes, and what I can do to fix it? Thanks in advance.
Here is my sessionInfo:
R version 3.4.1 (2017-06-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Gentoo/Linux

Matrix products: default
BLAS: /usr/lib64/blas/reference/libblas.so.0.0.0
LAPACK: /usr/lib64/lapack/reference/liblapack.so.0.0.0

locale:
 [1] LC_CTYPE=en_US       LC_NUMERIC=C         LC_TIME=en_US       
 [4] LC_COLLATE=en_US     LC_MONETARY=en_US    LC_MESSAGES=en_US   
 [7] LC_PAPER=en_US       LC_NAME=C            LC_ADDRESS=C        
[10] LC_TELEPHONE=C       LC_MEASUREMENT=en_US LC_IDENTIFICATION=C 

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] tidyr_0.8.0   scales_0.5.0  gridExtra_2.3 dplyr_0.7.4   ggplot2_2.2.1

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.16     assertthat_0.2.0 grid_3.4.1       plyr_1.8.4      
 [5] R6_2.2.2         gtable_0.2.0     magrittr_1.5     pillar_1.2.1    
 [9] rlang_0.2.0      lazyeval_0.2.1   bindrcpp_0.2.2   tools_3.4.1     
[13] glue_1.2.0       purrr_0.2.4      munsell_0.4.3    compiler_3.4.1  
[17] pkgconfig_2.0.1  colorspace_1.3-2 bindr_0.1.1      tibble_1.4.2    


--
Stuart Luppescu -- pixbuf .at. gmail.com
It is amazing how complete is the delusion that beauty is goodness.
  -- Leo Tolstoy
Reply all
Reply to author
Forward
0 new messages