loops - Split data frame to multiple data frame and apply lag to each data frame -
i have data frame 14 column (first 4 year, month, day, date; , next 10 10 variables). need split data frame each variable keeping 4 first columns (i.e., year, month, day, date) , naming each data frame according variable name. , need create 10 columns in each separated data frame filled 1 10 days lag respective variable column name q1,q2,…q10. new in r, therefore, not comfortable in looping through data frame. attaching data here. csv file.
i managed split data frame, produced data frame 1 column. but, said before, need keep first 4 columns in each separated data frame. , need add lagged value in each data frame.
df <- read.csv("df.csv", header=true) indx <- names(df[5:ncol(df)]) list2env( setnames( lapply(split(colnames(nc[,5:ncol(df)]), indx), function(x) df[x]), paste(sort(unique(indx)))), envir=.globalenv)
Comments
Post a Comment