0

I am a new user in R and now I have a question. I have a numeric object like:

QSW<- as.numeric(c(1:50))

This vector is the input of my function defined as:

HAR_ReCov<-function(vec){
x<-vec
ReCov_d = ReCov_w = ReCov_m = NULL

TT = length(x)
for (i in 30:TT){
ReCov_d[i] = x[(i-1)]
ReCov_w[i] = sum(x[(i-7):(i-2)],na.rm = T)/6 
ReCov_m[i] = sum(x[(i-29):(i-8)],na.rm = T)/22 
}
return = cbind(ReCov_d, ReCov_w, ReCov_m)
}

I want to know how can concatenate the name of my vector QSW with the names of my new variables, such that the names of the outputs be ReCoV_d_QSW, ReCoV_w_QSW, ReCoV_m_QSW.

Thanks for your help.

Eve Chanatasig
  • 397
  • 2
  • 10
  • 1
    Does this answer your question? [In R, how to get an object's name after it is sent to a function?](https://stackoverflow.com/questions/10520772/in-r-how-to-get-an-objects-name-after-it-is-sent-to-a-function) – Clemsang Feb 20 '20 at 12:12
  • Remove `return =` from your function. It doesn't do what you think it does. You could use the `return()` function but it's not necessary because the result from the last statement inside a function body is returned automatically. – Roland Feb 20 '20 at 12:27
  • 1
    @Clemsang, it was useful – Eve Chanatasig Feb 20 '20 at 15:18

0 Answers0