我正在尝试将一些风向数据分组到数据框的新列中的文本,遵循16个方向(N,NNE,NE等),但我似乎无法找出错误消息
这是代码:
RW_Baza[, Aspect_16] <- cut(RW_Baza$Aspect.grade,
breaks = c(-Inf, 11.25, 33.75, 56.25, 78.75, 101.25, 123.75, 146.25, 168.75, 191.25, 213.75, 236.25, 258.75, 281.25, 303.75, 326.25, 348.75, Inf),
labels = c("N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW", "N"),
right=FALSE)
我收到此错误消息:
在levels<-
(*tmp*
,值= if(nl == nL)as.character(标签),否则粘贴0(标签,:
不推荐使用因子中的重复级别。
答案 0 :(得分:1)
我认为你实际上是在收到警告,因为正如克里斯指出的那样,你在标签定义中重复了N
级别。
这样的事情对你来说可能会更好。它需要大于或等于348.75的任何角度并将其乘以-1,使其适合指向北方的-Inf - 11.25桶。
dir <- runif(1000, 0, 360)
# dir <- ifelse(dir >= 348.75, dir * -1, dir) # Removed to prevent overwriting data
cut(ifelse(dir >= 348.75, dir * -1, dir),
breaks = c(-Inf, 11.25, 33.75, 56.25, 78.75, 101.25, 123.75, 146.25, 168.75, 191.25, 213.75, 236.25, 258.75, 281.25, 303.75, 326.25, 348.75),
labels = c("N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"),
right=FALSE)
dir <- c(348.75, 348, 350, 1)
#dir <- ifelse(dir >= 348.75, dir * -1, dir) # Removed to prevent overwriting data
cut(ifelse(dir >= 348.75, dir * -1, dir),
breaks = c(-Inf, 11.25, 33.75, 56.25, 78.75, 101.25, 123.75, 146.25, 168.75, 191.25, 213.75, 236.25, 258.75, 281.25, 303.75, 326.25, 348.75),
labels = c("N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"),
right=FALSE)