R script for adaptive data