Growth Rate of all columns

319 Views Asked by At

I have a dataframe which consist of 23 variables. I want to calculate the growth rate by lag 1 of the first 22 variables. I tried to make a list mylist of all 22 columns and then use lapply function but it is not working. The dataset is called data_nse

  temp4 <- lapply(mylist,function(x){ 
  data_nse$x <- (x-lag(x,1))/lag(x,1)  
 x})

I get the following error

>  Error in attr(x, "tsp") <- c(1, NROW(x), 1) :    invalid time series
> parameters specified

What is the correct and efficient way to do this? I am new to R.

Thanks in advance!

0

There are 0 best solutions below