[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("","","","","","","","","")
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)))))
#[1] "SKH1" "SKH1" "SKH1" "SKH2" "SKH2" "SKH2" "SKH2" "SKH3" "SKH3"

#or if the column is:
dat1 <- data.frame(iprange =c(" -", " -"))
 dat1[,1] <- factor(dat1[,1],labels=paste0("SKH",1:2))

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 - then SKH1 
     if - 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. 


More information about the R-help mailing list