[R] Assiging name to ip address range
arun
smartpink111 at yahoo.com
Thu Nov 28 18:12:09 CET 2013
Hi ,
If it is like:
vec1 <- c("10.20.30.01","10.20.30.02","10.20.30.40","10.20.30.41","10.20.30.45","10.20.30.254","10.20.30.255","10.20.30.256","10.20.30.313")
vec2 <- as.numeric(paste0(gsub("^\\d{2}\\.\\d{2}\\.(\\d{2}\\.).*","\\1",vec1),sprintf("%03d",as.numeric(gsub("^\\d{2}\\.\\d{2}\\.\\d{2}\\.","",vec1)))))
as.character(cut(vec2,breaks=c(30,30.040,30.255,30.313),labels=paste0("SKH",1:3)))
#[1] "SKH1" "SKH1" "SKH1" "SKH2" "SKH2" "SKH2" "SKH2" "SKH3" "SKH3"
#or if the column is:
dat1 <- data.frame(iprange =c("10.20.30.01 - 10.20.30.40", "10.20.30.40 - 10.20.30.255"))
dat1[,1] <- factor(dat1[,1],labels=paste0("SKH",1:2))
A.K.
I have an ip address column in my dataset which r read as factor.I want to create a new variable for a range
like if 10.20.30.01 - 10.20.30.40 then SKH1
if 10.20.30.40 -10.20.30.255 then SKH2 & so on
10.20 will always remian same ,other values will change
I have around 500 values which i want to assign as per ip address.i
am not able to use greater than or less than function .please advise how
to do that.
Thanks!!
More information about the R-help
mailing list