Use paste function with apply families I am trying to assign different window sizes to my SNPs dataset to identify regions under selection.

this is the head of my data

head(snp_ids)
   snp_id   chr  pos
Chr01__912    1  912
Chr01__944    1  944
Chr01__1107   1 1107
Chr01__1118   1 1118
Chr01__1146   1 1146
Chr01__1160   1 1160

class(snp_ids)
data.frame


I have chosen 4 different window sizes, win_size &lt;- c(15000, 30000, 50000, 100000).
I have assigned each of these different window sizes to my snp_ids dataset to identify how many SNPs are distributed within each window by looping through each window size 

for (i in 1:length(win_size)){
  windows &lt;- sapply(snp_ids$pos, function(x) (ceiling(x/win_size[i])))
}
Not clear what we are trying to do, but here is the solution using lapply that should replicate your existing forloop.

# example input data
snp_ids &lt;- read.table(text = "
snp_id  chr  pos
Chr01__912   1  912
Chr01__944   1  944
Chr01__1107  1 1107
Chr01__1118  1 1118
Chr01__1146  1 1146
Chr01__1160  1 1160", header = TRUE)

# window sizes to loop through
win_size &lt;- c(15000, 30000, 50000, 100000)

res &lt;- cbind(snp_ids,
             data.frame(
               lapply(setNames(win_size, paste("window", win_size, sep = "_")), function(w)
                 as.numeric(paste(snp_ids$chr, ceiling(snp_ids$pos/w), sep = "."))
               )))

# result
res
#        snp_id chr  pos window_15000 window_30000 window_50000 window_1e.05
# 1  Chr01__912   1  912          1.1          1.1          1.1          1.1
# 2  Chr01__944   1  944          1.1          1.1          1.1          1.1
# 3 Chr01__1107   1 1107          1.1          1.1          1.1          1.1
# 4 Chr01__1118   1 1118          1.1          1.1          1.1          1.1
# 5 Chr01__1146   1 1146          1.1          1.1          1.1          1.1
# 6 Chr01__1160   1 1160          1.1          1.1          1.1          1.1




Edit: If we really want to use forloop, then try below:

for (i in win_size){
  windows &lt;- ceiling(snp_ids$pos/i)
  snp_ids[, paste0("window_", i)] &lt;- as.numeric(paste(snp_ids$chr, windows, sep = "."))
}