sachinthaka.abeywardana at allianz.com.au
2010-Nov-10 05:09 UTC
[R] concatenating a string to a column
Hi All, Suppose I want to concatenate a zero to all the values to a column called period in data frame A. I want to do the following but the following command actually deletes the entire column altogether. A$period<-cat(A$period,"0",sep=""); Any help would be appreciated. Thanks, Sachin p.s. sorry about the corporate notice. --- Please consider the environment before printing this email --- Allianz - Best General Insurance Company of the Year 2010* Allianz - General Insurance Company of the Year 2009+ * Australian Banking and Finance Insurance Awards + Australia and New Zealand Insurance Industry Awards This email and any attachments has been sent by Allianz Australia Insurance Limited (ABN 15 000 122 850) and is intended solely for the addressee. It is confidential, may contain personal information and may be subject to legal professional privilege. Unauthorised use is strictly prohibited and may be unlawful. If you have received this by mistake, confidentiality and any legal privilege are not waived or lost and we ask that you contact the sender and delete and destroy this and any other copies. In relation to any legal use you may make of the contents of this email, you must ensure that you comply with the Privacy Act (Cth) 1988 and you should note that the contents may be subject to copyright and therefore may not be reproduced, communicated or adapted without the express consent of the owner of the copyright. Allianz will not be liable in connection with any data corruption, interruption, delay, computer virus or unauthorised access or amendment to the contents of this email. If this email is a commercial electronic message and you would prefer not to receive further commercial electronic messages from Allianz, please forward a copy of this email to unsubscribe at allianz.com.au with the word unsubscribe in the subject header.
You want the paste command (cat is for printing to the console)... A$period <- paste(A$period, 0, sep="") Michael On 10 November 2010 16:09, <sachinthaka.abeywardana at allianz.com.au> wrote:> > Hi All, > > Suppose I want to concatenate a zero to all the values to a column called > period in data frame A. I want to do the following but the following > command actually deletes the entire column altogether. > > ?A$period<-cat(A$period,"0",sep=""); > > Any help would be appreciated. > > Thanks, > Sachin > p.s. sorry about the corporate notice. > > --- Please consider the environment before printing this email --- > > Allianz - Best General Insurance Company of the Year 2010* > Allianz - General Insurance Company of the Year 2009+ > > * Australian Banking and Finance Insurance Awards > + Australia and New Zealand Insurance Industry Awards > > This email and any attachments has been sent by Allianz Australia Insurance Limited (ABN 15 000 122 850) and is intended solely for the addressee. It is confidential, may contain personal information and may be subject to legal professional privilege. Unauthorised use is strictly prohibited and may be unlawful. If you have received this by mistake, confidentiality and any legal privilege are not waived or lost and we ask that you contact the sender and delete and destroy this and any other copies. In relation to any legal use you may make of the contents of this email, you must ensure that you comply with the Privacy Act (Cth) 1988 and you should note that the contents may be subject to copyright and therefore may not be reproduced, communicated or adapted without the express consent of the owner of the copyright. > Allianz will not be liable in connection with any data corruption, interruption, delay, computer virus or unauthorised access or amendment to the contents of this email. If this email is a commercial electronic message and you would prefer not to receive further commercial electronic messages from Allianz, please forward a copy of this email to unsubscribe at allianz.com.au with the word unsubscribe in the subject header. > > ______________________________________________ > R-help at 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. >
On Tue, Nov 9, 2010 at 9:09 PM, <sachinthaka.abeywardana at allianz.com.au> wrote:> > Hi All, > > Suppose I want to concatenate a zero to all the values to a column called > period in data frame A. I want to do the following but the following > command actually deletes the entire column altogether. > > ?A$period<-cat(A$period,"0",sep="");cat returns NULL, so you get NULL in A$period. try A$period<-paste(A$period,"0",sep=""); Of course, if A$period are integer numbers, a simple way of adding a zero is to multiply everything by 10. Peter
Try on these lines library(MASS) data(Boston) Boston$crim<-paste(Boston$crim,"Test",sep="-") -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of sachinthaka.abeywardana at allianz.com.au Sent: 10 November 2010 10:39 To: R-help Forum Subject: [R] concatenating a string to a column Hi All, Suppose I want to concatenate a zero to all the values to a column called period in data frame A. I want to do the following but the following command actually deletes the entire column altogether. A$period<-cat(A$period,"0",sep=""); Any help would be appreciated. Thanks, Sachin p.s. sorry about the corporate notice. --- Please consider the environment before printing this email --- Allianz - Best General Insurance Company of the Year 2010* Allianz - General Insurance Company of the Year 2009+ * Australian Banking and Finance Insurance Awards + Australia and New Zealand Insurance Industry Awards This email and any attachments has been sent by Allianz Australia Insurance Limited (ABN 15 000 122 850) and is intended solely for the addressee. It is confidential, may contain personal information and may be subject to legal professional privilege. Unauthorised use is strictly prohibited and may be unlawful. If you have received this by mistake, confidentiality and any legal privilege are not waived or lost and we ask that you contact the sender and delete and destroy this and any other copies. In relation to any legal use you may make of the contents of this email, you must ensure that you comply with the Privacy Act (Cth) 1988 and you should note that the contents may be subject to copyright and therefore may not be reproduced, communicated or adapted without the express consent of the owner of the copyright. Allianz will not be liable in connection with any data corruption, interruption, delay, computer virus or unauthorised access or amendment to the contents of this email. If this email is a commercial electronic message and you would prefer not to receive further commercial electronic messages from Allianz, please forward a copy of this email to unsubscribe at allianz.com.au with the word unsubscribe in the subject header. ______________________________________________ R-help at 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.