Hi Magali, I confess that I still not figured out what you want, but try this:
datatry2=transform(datatry,DIS=as.numeric(as.character(paste(datatry[,1],datatry[,2],sep="")))) bests milton On Wed, Jan 20, 2010 at 11:14 PM, teurlai magali <teurlai...@yahoo.fr>wrote: > Sorry I forgot the subject in my previous post > > Here is an example of data : province and district code of 4 locations > > datatry=matrix(c(8,12,3,3,1,1,16,1),4,2) > colnames(datatry)<-c("PROCODE","DISCODE") > > DISCODE is not unique for each location (there is a distrcit nb 1 in each > province) > I want to create a third column (DIS) which would contain a unique district > code for each location that would be the appended values of the province > code and the district code, and that would be a numeric value (not a > character) > > here is my try (thanks to Henrique Dallazuanna!) > > DIS=rep(0,nrow(datatry)) > datatry=cbind(datatry,DIS) > datatry2=transform(datatry,DIS=paste(datatry[,1],datatry[,2])); > > However it creates a string, and the 2 codes are separated by an empty > space, which I didn't manage to supress using different values for arguments > "sep" and "collapse". > > i'll try to see other options to concatenate 2 numeric values into a third > one. > > Thanks > > > --- En date de : Jeu 21.1.10, Henrique Dallazuanna <www...@gmail.com> a > écrit : > > De: Henrique Dallazuanna <www...@gmail.com> > Objet: Re: [R] (no subject) > À: "teurlai magali" <teurlai...@yahoo.fr> > Cc: r-help@r-project.org > Date: Jeudi 21 Janvier 2010, 3h41 > > transform(DF, District_Unique = paste(Province, District, collapse = '')) > > On Thu, Jan 21, 2010 at 12:34 AM, teurlai magali <teurlai...@yahoo.fr> > wrote: > > Hi > > > > is there a way in R to create a new column vector with the numbers of 2 > others columns simply appended? > > > > Example : I have a column with provinces codes (1 to 19) > > I have a second column with districts codes (1 to ##, depending on the > province) > > I want to create a third column with a code that would be unique for each > district: > > > > Province District District_Unique > > 1 1 11 > > 1 2 12 > > 13 2 132 > > > > I can create a loop, but it becomes complicated with numerous data > > > > Thanks for your help > > > > > > > > > > > > [[alternative HTML version deleted]] > > > > > > ______________________________________________ > > 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<http://www.r-project.org/posting-guide.html> > > and provide commented, minimal, self-contained, reproducible code. > > > > > > > > -- > Henrique Dallazuanna > Curitiba-Paraná-Brasil > 25° 25' 40" S 49° 16' 22" O > > > > > [[alternative HTML version deleted]] > > > ______________________________________________ > 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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > > [[alternative HTML version deleted]]
______________________________________________ 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.