У меня есть вектор значений начального и конечного ангелов от 0 до 360. Я хотел бы иметь дополнительный столбец, в котором указывается, в каком секторе (рассмотрим 12 секторов) мои переменные.
сектора должны быть определеныкак: (15:45], (45,75],(75,105], ..., (345,15]
test = structure(list(start = c(4, 67, 13, 35, 54, 0), end = c(23, 84,
30, 52, 71, 0)), row.names = 2:7, class = "data.frame")
Для моего тестового примера я подумал, что мне нужно перебрать количество строк:
for( i in 1:nrow(test)){
if(test$start[i] <= 15 | test$start[i] >345){test$sector_start[i] = 12}
else if(test$start[i] > 15 & test$start[i] <= 45){test$sector_start[i] = 1}
else if(test$start[i] > 45 & test$start[i] <= 75){test$sector_start[i] = 2}
else if(test$start[i] > 75 & test$start[i] <= 105){test$sector_start[i] = 3}
else if(test$start[i] > 105 & test$start[i] <= 135){test$sector_start[i] = 4}
else if(test$start[i] > 135 & test$start[i] <= 165){test$sector_start[i] = 5}
else if(test$start[i] > 165 & test$start[i] <= 195){test$sector_start[i] = 6}
else if(test$start[i] > 195 & test$start[i] <= 225){test$sector_start[i] = 7}
else if(test$start[i] > 225 & test$start[i] <= 255){test$sector_start[i] = 8}
else if(test$start[i] > 255 & test$start[i] <= 285){test$sector_start[i] = 9}
else if(test$start[i] > 285 & test$start[i] <= 315){test$sector_start[i] = 10}
else if(test$start[i] > 315 & test$start[i] <= 345){test$sector_start[i] = 11}
if(test$end[i] <= 15 | test$end[i] >345){test$sector_end[i] = 12}
else if(test$end[i] > 15 & test$end[i] <= 45){test$sector_end[i] = 1}
else if(test$end[i] > 45 & test$end[i] <= 75){test$sector_end[i] = 2}
else if(test$end[i] > 75 & test$end[i] <= 105){test$sector_end[i] = 3}
else if(test$end[i] > 105 & test$end[i] <= 135){test$sector_end[i] = 4}
else if(test$end[i] > 135 & test$end[i] <= 165){test$sector_end[i] = 5}
else if(test$end[i] > 165 & test$end[i] <= 195){test$sector_end[i] = 6}
else if(test$end[i] > 195 & test$end[i] <= 225){test$sector_end[i] = 7}
else if(test$end[i] > 225 & test$end[i] <= 255){test$sector_end[i] = 8}
else if(test$end[i] > 255 & test$end[i] <= 285){test$sector_end[i] = 9}
else if(test$end[i] > 285 & test$end[i] <= 315){test$sector_end[i] = 10}
else if(test$end[i] > 315 & test$end[i] <= 345){test$sector_end[i] = 11}
}
здесь я мог бы добавить 2 столбца к test
, чтоговорит мне мои углы в каком секторе.Я ищу более разумный способ сделать это, чтобы у меня была возможность изменить количество секторов, например, до 24 секторов.