Quantcast
Viewing all articles
Browse latest Browse all 57

How to divide the columns in a time series by their first value in R?

I have the code below working. But there must be a better way.

file <- "http://s3.amazonaws.com/assets.datacamp.com/production/course_1127/datasets/tmp_file.csv"x <- read.csv(file = file)ts <- xts(x = x,  order.by = as.Date(rownames(x), "%m/%d/%Y"))cd=coredata(ts)for (j in 1:length(names(ts)))  cd[,j]<-cd[,j]/cd[1,j]for (j in 1:length(names(ts))) ts[,j]<-cd[,j]

Viewing all articles
Browse latest Browse all 57

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>