Guest User

Untitled

a guest
May 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. id <- c(rep(1, times = 10), rep(3, times = 10), rep(4, times = 10))
  2. time <- c(1,2,3,4,5,6,7,8,9,10)
  3. weight <- runif(30, min = 50, max = 100)
  4. dataframe <- data.frame(id, time, weight)
  5.  
  6. coef(lm(weight~time, data = dataframe))[2]
  7.  
  8. sapply(split(dataframe, dataframe$id), function(i) coef(lm(weight ~ time, data = i))[2])
  9. # 1.time 3.time 4.time
  10. # 1.48800159 -0.05921987 -2.57523482
Add Comment
Please, Sign In to add comment