You can fix the space problem by using '[^[:digit:]]' instead of '[[:alpha:]]' and '[^[:alpha:]]' instead of '[[:digit:]]'
On Wed, Nov 12, 2008 at 5:10 PM, Peter Alspach <[EMAIL PROTECTED]> wrote: > Tena koe > > Try: > > gsub('[[:alpha:]]', '', unlist(DATA)) and > gsub('[[:digit:]]', '', unlist(DATA)) > > unlist(DATA) since it looks like DATA maybe a dataframe. > > You are still left with the spaces, but these can be readily removed. > Someone else may offer a better solution. > > HTH ... > > Peter Alspach > >> -----Original Message----- >> From: [EMAIL PROTECTED] >> [mailto:[EMAIL PROTECTED] On Behalf Of CE.KA >> Sent: Thursday, 13 November 2008 10:10 a.m. >> To: r-help@r-project.org >> Subject: [R] separate a variable in several variables >> >> >> Hello R users, >> Imagine the data frame DATA with the variable x which is >> composed by numeric and alpha caracters. >> >> > DATA >> x >> 1 12F >> 2 13 AD >> 3 356PO >> 4 1D >> 5 GRT >> 6 PO52 >> 7 LN4Z >> >> Is there a way to separarate x in 2 variables: >> y: only numeric caracters >> z: only alpha caracters >> For exemple: >> x y z >> 1 12F 12 F >> 2 13 AD 13 AD >> 3 356PO 356 PO >> 4 1D 1 D >> 5 GRT 0 GRT >> 6 PO52 52 PO >> 7 LN4Z 4 LNZ >> >> Kind regards >> -- >> View this message in context: >> http://www.nabble.com/separate-a-variable-in-several-variables >> -tp20469491p20469491.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > The contents of this e-mail are privileged and/or confidential to the named > recipient and are not to be used by any other person and/or organisation. > If you have received this e-mail in error, please notify the sender and > delete > all material pertaining to this e-mail. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.