Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

Is it possible to populate R dataframe with two interdependent columns

$
0
0

I am try to use R to calculate sales as a function of inventory as a function of sales. See below data snapshot. Is there anyway to calculate this?

  • Group, Day and Sell_Thru are independent variables
  • Inv = lag(Inv,1) – lag(Sales,1)
  • Sales = (Inv * Sell Thru)

I am given this data frame:

Group <- c("A","A","A","A","A","B","B","B","B","B")
Day <- c(1,2,3,4,5,1,2,3,4,5)
Inventory <- c(50000,NA,NA,NA,NA,20000,NA,NA,NA,NA)
Sell_Thru <- c(.05,.06,.07,.08,.09,.05,.06,.04,.11,.01)
Sales <- c(NA,NA,NA,NA,NA,NA,NA,NA,NA,NA)


inv_proj <- data.frame(Group, Day,Inventory,Sell_Thru,Sales)

Trying to populate this data frame

Group <- c("A","A","A","A","A","B","B","B","B","B")
Day <- c(1,2,3,4,5,1,2,3,4,5)
Inventory <-c(50000,47500,44650,41525,38203,20000,19000,17860,17146,15260)
Sell_Thru <- c(.05,.06,.07,.08,.09,.05,.06,.04,.11,.01)
Sales <- c(2500,2850,3126,3322,3438,1000,1140,714,1886,153)

inv_proj <- data.frame(Group, Day,Inventory,Sell_Thru,Sales)

Viewing all articles
Browse latest Browse all 201945

Trending Articles



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