Use get
to fetch the value of a variable given its name. So in your code above, replace paste0("xh",i)
with get(paste0("xh",i))
, and likewise for yh
. In other words, try
poly<-lapply(1:100, function(i) cbind(get(paste0("xh",i)), get(paste0("yh",i))))
(I can't help wondering why you're using separate variables xh1
, xh2
, ... instead of a matrix or data frame xh
with columns 1, 2, ...)