Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non alphanumeric characters in R

Tags:

r

For uppercase, lowercase letters and 10-digits I can generate a vector that contains all letters or 10-digit number as follow:

A <- LETTERS[0:26]
B <- letters[0:26]
C <- seq(0,9)

I wonder whether there is a similar function for non-alphanumeric characters.

~!@#$%^&*_-+=`|\(){}[]:;"'<>,.?/

I tried

D <- c("~","!","@","#","$","%","^", "&","*","_","-","+","=","`","|","\","(",")","{","}","[","]",":",";",""","'","<",">",",",".","?","/")

Thanks

like image 401
useR Avatar asked Sep 01 '25 03:09

useR


2 Answers

This is another option. Generate all ascii characters, then filter out the non punctuation with regular expressions.

ascii <- rawToChar(as.raw(0:127), multiple=TRUE)
ascii[grepl('[[:punct:]]', ascii)]

# [1] "!"  "\"" "#"  "$"  "%"  "&"  "'"  "("  ")"  "*"  "+"  ","  "-"  "."  "/"  ":"  ";"  "<"  "="  ">"  "?"  "@" 
# [23] "["  "\\" "]"  "^"  "_"  "`"  "{"  "|"  "}"  "~" 
like image 138
Matthew Plourde Avatar answered Sep 02 '25 17:09

Matthew Plourde


This might be useful . . The ASCII character set is arranged in ranges of similar types of characters (letters, etc).

http://datadebrief.blogspot.com/2011/03/ascii-code-table-in-r.html

like image 29
Kid Rocket Avatar answered Sep 02 '25 17:09

Kid Rocket