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