0
votes

I have wind direction measurements and would like to assign labels to the numeric measurements (in degrees (0-360)).

I tried to use cut():

meteo$DWIND <- cut(meteo$DWND, breaks = c(0,22.5,67.5,112.5,157.5,202.5,247.5,292.5,337.5,360), labels = c("N", "NE", "E","SE","S","SW","W","NW","N"))

But this throws the following warning:

In levels<-(*tmp*, value = if (nl == nL) as.character(labels) else paste0(labels, : duplicated levels in factors are deprecated

I understand that I use the label "N" twice and cut somehow does not like that idea. But this is exactly what I want. To assign the same label "N" to both bins 0-22.5 and 337.5-360.

Could you help me finding a way to achieve this?

1
Why not labels = c("N", "NE", "E","SE","S","SW","W","NW","N2") followed by meteo$DWIND[meteo$DWIND=="N2"] = "N" ?G5W

1 Answers

0
votes

You could use this trick.

meteo$DWIND <- as.character(cut(meteo$DWIND, 
                                breaks=c(0,22.5,67.5,112.5,157.5,202.5,247.5,292.5,337.5,360), 
                                labels=c("N", "NE", "E","SE","S","SW","W","NW","Nfake")))
meteo$DWIND <- as.factor(ifelse(meteo$DWIND == "Nfake", "N", meteo$DWIND))