Re: [R] How to evaluate sequence of strings like this
Thank you. It is working well. On Sunday, 8 December 2013 11:13 PM, arun kirshna [via R] wrote: Hi, You could do without "eval(parse(.." mydat <- data.frame(Centercode=letters[1:5],FSUSN=letters[6:10],Round=letters[11:15],stringsAsFactors=FALSE) mydat1 <- paste(mydat$Centercode, mydat$FSUSN,mydat$Round,sep="")  mydat2 <- as.character(interaction(mydat,sep=""))  identical(mydat1,mydat2) #[1] TRUE #or mydat3 <- do.call(paste0,mydat) identical(mydat1,mydat2) #[1] TRUE A.K. On Sunday, December 8, 2013 8:58 AM, kingsly <[hidden email]> wrote: Hello Dear R community,  This is my problem. I have a data set (dataframe) called "mydat". It consist of 3 numerical variable. They are Centrecode, FSUSN and Round. I want to create unique ID by combining these 3 variables. Follwing commands gives me what I need. mydat1 <- paste(mydat$Centrecode, mydat$FSUSN,mydat$Round,sep="") newds <- data.frame(mydat1)   For a large data set, I don't want to write like this ...   "mydat$Centrecode, mydat$FSUSN,mydat$Round". So, I tried to automate using following code.  nvar <- paste("mydat","$",names(mydat)[1:3],sep="") mydat1 <- paste(eval(parse(text=nvar))) newds <- data.frame(mydat1_u)  I am finding problem in the second line. Please help me. Thank you for your kind help. -- View this message in context: http://r.789695.n4.nabble.com/How-to-evaluate-sequence-of-strings-like-this-tp4681823.html Sent from the R help mailing list archive at Nabble.com.    [[alternative HTML version deleted]] __ [hidden email] 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. __ [hidden email] 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. If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/How-to-evaluate-sequence-of-strings-like-this-tp4681823p4681833.html To start a new topic under R help, email ml-node+s789695n78969...@n4.nabble.com To unsubscribe from R help, click here. NAML -- View this message in context: http://r.789695.n4.nabble.com/How-to-evaluate-sequence-of-strings-like-this-tp4681823p4681841.html Sent from the R help mailing list archive at Nabble.com. [[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.
Re: [R] How to evaluate sequence of strings like this
Hi, You could do without "eval(parse(.." mydat <- data.frame(Centercode=letters[1:5],FSUSN=letters[6:10],Round=letters[11:15],stringsAsFactors=FALSE) mydat1 <- paste(mydat$Centercode, mydat$FSUSN,mydat$Round,sep="") mydat2 <- as.character(interaction(mydat,sep="")) identical(mydat1,mydat2) #[1] TRUE #or mydat3 <- do.call(paste0,mydat) identical(mydat1,mydat2) #[1] TRUE A.K. On Sunday, December 8, 2013 8:58 AM, kingsly wrote: Hello Dear R community, This is my problem. I have a data set (dataframe) called "mydat". It consist of 3 numerical variable. They are Centrecode, FSUSN and Round. I want to create unique ID by combining these 3 variables. Follwing commands gives me what I need. mydat1 <- paste(mydat$Centrecode, mydat$FSUSN,mydat$Round,sep="") newds <- data.frame(mydat1) For a large data set, I don't want to write like this ... "mydat$Centrecode, mydat$FSUSN,mydat$Round". So, I tried to automate using following code. nvar <- paste("mydat","$",names(mydat)[1:3],sep="") mydat1 <- paste(eval(parse(text=nvar))) newds <- data.frame(mydat1_u) I am finding problem in the second line. Please help me. Thank you for your kind help. -- View this message in context: http://r.789695.n4.nabble.com/How-to-evaluate-sequence-of-strings-like-this-tp4681823.html Sent from the R help mailing list archive at Nabble.com. [[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. __ 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.
Re: [R] How to evaluate sequence of strings like this
Tena koe Try apply(mydat, 1, paste, collapse='') HTH Peter Alspach From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of kingsly [ecoking...@yahoo.co.in] Sent: Monday, December 09, 2013 12:22 AM To: r-help@r-project.org Subject: [R] How to evaluate sequence of strings like this Hello Dear R community, This is my problem. I have a data set (dataframe) called "mydat". It consist of 3 numerical variable. They are Centrecode, FSUSN and Round. I want to create unique ID by combining these 3 variables. Follwing commands gives me what I need. mydat1 <- paste(mydat$Centrecode, mydat$FSUSN,mydat$Round,sep="") newds <- data.frame(mydat1) For a large data set, I don't want to write like this ... "mydat$Centrecode, mydat$FSUSN,mydat$Round". So, I tried to automate using following code. nvar <- paste("mydat","$",names(mydat)[1:3],sep="") mydat1 <- paste(eval(parse(text=nvar))) newds <- data.frame(mydat1_u) I am finding problem in the second line. Please help me. Thank you for your kind help. -- View this message in context: http://r.789695.n4.nabble.com/How-to-evaluate-sequence-of-strings-like-this-tp4681823.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] The contents of this e-mail are confidential and may be ...{{dropped:14}} __ 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] How to evaluate sequence of strings like this
Hello Dear R community,  This is my problem. I have a data set (dataframe) called "mydat". It consist of 3 numerical variable. They are Centrecode, FSUSN and Round. I want to create unique ID by combining these 3 variables. Follwing commands gives me what I need. mydat1 <- paste(mydat$Centrecode, mydat$FSUSN,mydat$Round,sep="") newds <- data.frame(mydat1)   For a large data set, I don't want to write like this ...   "mydat$Centrecode, mydat$FSUSN,mydat$Round". So, I tried to automate using following code.  nvar <- paste("mydat","$",names(mydat)[1:3],sep="") mydat1 <- paste(eval(parse(text=nvar))) newds <- data.frame(mydat1_u)  I am finding problem in the second line. Please help me. Thank you for your kind help. -- View this message in context: http://r.789695.n4.nabble.com/How-to-evaluate-sequence-of-strings-like-this-tp4681823.html Sent from the R help mailing list archive at Nabble.com. [[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.