[R] Remove double quotation marks
Dear All, I am not sure how to remove double quotation marks in a string, e.g., paste(variable, 1). Can anybody please help me solve it? Thank you in advance. Lisa -- View this message in context: http://n4.nabble.com/Remove-double-quotation-marks-tp990502p990502.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.
Re: [R] Remove double quotation marks
On 29/12/2009 1:16 PM, Lisa wrote: Dear All, I am not sure how to remove double quotation marks in a string, e.g., paste(variable, 1). Can anybody please help me solve it? Thank you in advance. I think you need to tell us what is wrong with what you get from that. When I look at the result: cat(paste(variable, 1), \n) variable 1 I see no quotation marks. (If you use print() you'll see some, but they aren't part of the string, they are just used in the default display by print().) Duncan Murdoch __ 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] Remove double quotation marks
Thank you for your reply. But in the following case, “cat()” or “print()” doesn’t work. data.frame(cbind(variable 1, variable 2, cat(paste(variable, x), \n))), where x is a random number generated by other R script. Lisa Duncan Murdoch wrote: On 29/12/2009 1:16 PM, Lisa wrote: Dear All, I am not sure how to remove double quotation marks in a string, e.g., paste(variable, 1). Can anybody please help me solve it? Thank you in advance. I think you need to tell us what is wrong with what you get from that. When I look at the result: cat(paste(variable, 1), \n) variable 1 I see no quotation marks. (If you use print() you'll see some, but they aren't part of the string, they are just used in the default display by print().) Duncan Murdoch __ 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. -- View this message in context: http://n4.nabble.com/Remove-double-quotation-marks-tp990502p990516.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.
Re: [R] Remove double quotation marks
On Tue, Dec 29, 2009 at 6:31 PM, Lisa lisa...@gmail.com wrote: Thank you for your reply. But in the following case, “cat()” or “print()” doesn’t work. data.frame(cbind(variable 1, variable 2, cat(paste(variable, x), \n))), where x is a random number generated by other R script. Lisa Yes, because you are Doing It Wrong. If you have data that is indexed by an integer, don't store it in variables called variable1, variable2 etc, because very soon you will be posting a message to R-help that is covered in the R FAQ... Store it in a list: v = list() v[[1]] = c(1,2,3,4,5) v[[2]] = c(4,5,6,7,8,9,9,9) then you can do v[[i]] for integer values of i. If you really really must get values of variable by name, perhaps because someone has given you a data file with variables called variable1 to variable99, then use the paste() construction together with the 'get' function: [ not tested, but should work ] v1=99 v2=102 i=2 get(paste(v,i,sep=)) [1] 102 Barry __ 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] Remove double quotation marks
?get something like: v1 - c(0, 1, 0) v2 - c(1, 1, 0) v3 - c(2, 1, 2) v4 - c(2, 2, 1) v5 - c(0, 1, 1) x - 5 cbind(v1, v2, get(paste('v', x, sep=''))) v1 v2 [1,] 0 1 0 [2,] 1 1 1 [3,] 0 0 1 On Tue, Dec 29, 2009 at 3:54 PM, Lisa lisa...@gmail.com wrote: Thank you for your help. But here I just want to combine some vectors by column based on the numbers determined by other R script. For example, I have five vectors: v1 - c(0, 1, 0) v2 - c(1, 1, 0) v3 - c(2, 1, 2) v4 - c(2, 2, 1) v5 - c(0, 1, 1) If I am going to combine the first two vectors, and one more other vector determined by my other R script, say, vector 5. Then my R script is x - 5 cbind(v1, v2, paste(v, x, sep = )) The output is v1 v2 [1,] 0 1 v5 [2,] 1 1 v5 [3,] 0 0 v5 This is not what I want. I want to get this: v1 v2 v5 [1,] 0 1 0 [2,] 1 1 1 [3,] 0 0 1 Can you give me further suggestions or comments? Thanks a lot. Lisa Barry Rowlingson wrote: On Tue, Dec 29, 2009 at 6:31 PM, Lisa lisa...@gmail.com wrote: Thank you for your reply. But in the following case, cat() or print() doesnt work. data.frame(cbind(variable 1, variable 2, cat(paste(variable, x), \n))), where x is a random number generated by other R script. Lisa Yes, because you are Doing It Wrong. If you have data that is indexed by an integer, don't store it in variables called variable1, variable2 etc, because very soon you will be posting a message to R-help that is covered in the R FAQ... Store it in a list: v = list() v[[1]] = c(1,2,3,4,5) v[[2]] = c(4,5,6,7,8,9,9,9) then you can do v[[i]] for integer values of i. If you really really must get values of variable by name, perhaps because someone has given you a data file with variables called variable1 to variable99, then use the paste() construction together with the 'get' function: [ not tested, but should work ] v1=99 v2=102 i=2 get(paste(v,i,sep=)) [1] 102 Barry __ 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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://n4.nabble.com/Remove-double-quotation-marks-tp990502p990586.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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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] Remove double quotation marks
Thanks. I also need column name v5. Lisa jholtman wrote: ?get something like: v1 - c(0, 1, 0) v2 - c(1, 1, 0) v3 - c(2, 1, 2) v4 - c(2, 2, 1) v5 - c(0, 1, 1) x - 5 cbind(v1, v2, get(paste('v', x, sep=''))) v1 v2 [1,] 0 1 0 [2,] 1 1 1 [3,] 0 0 1 On Tue, Dec 29, 2009 at 3:54 PM, Lisa lisa...@gmail.com wrote: Thank you for your help. But here I just want to combine some vectors by column based on the numbers determined by other R script. For example, I have five vectors: v1 - c(0, 1, 0) v2 - c(1, 1, 0) v3 - c(2, 1, 2) v4 - c(2, 2, 1) v5 - c(0, 1, 1) If I am going to combine the first two vectors, and one more other vector determined by my other R script, say, vector 5. Then my R script is x - 5 cbind(v1, v2, paste(v, x, sep = )) The output is v1 v2 [1,] 0 1 v5 [2,] 1 1 v5 [3,] 0 0 v5 This is not what I want. I want to get this: v1 v2 v5 [1,] 0 1 0 [2,] 1 1 1 [3,] 0 0 1 Can you give me further suggestions or comments? Thanks a lot. Lisa Barry Rowlingson wrote: On Tue, Dec 29, 2009 at 6:31 PM, Lisa lisa...@gmail.com wrote: Thank you for your reply. But in the following case, cat() or print() doesnt work. data.frame(cbind(variable 1, variable 2, cat(paste(variable, x), \n))), where x is a random number generated by other R script. Lisa Yes, because you are Doing It Wrong. If you have data that is indexed by an integer, don't store it in variables called variable1, variable2 etc, because very soon you will be posting a message to R-help that is covered in the R FAQ... Store it in a list: v = list() v[[1]] = c(1,2,3,4,5) v[[2]] = c(4,5,6,7,8,9,9,9) then you can do v[[i]] for integer values of i. If you really really must get values of variable by name, perhaps because someone has given you a data file with variables called variable1 to variable99, then use the paste() construction together with the 'get' function: [ not tested, but should work ] v1=99 v2=102 i=2 get(paste(v,i,sep=)) [1] 102 Barry __ 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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://n4.nabble.com/Remove-double-quotation-marks-tp990502p990586.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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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. -- View this message in context: http://n4.nabble.com/Remove-double-quotation-marks-tp990502p990591.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.
Re: [R] Remove double quotation marks
It seems from your example that you're assuming all of the vectors have the same length. If this is the case, then a data.frame might be your friend. df - data.frame( v1 = c(0, 1, 0), v2 = c(1, 1, 0), v3 = c(2, 1, 2), v4 = c(2, 2, 1), v5 = c(0, 1, 1) ) x - 5 get.var - c(v1, v2, paste(v, x, sep=)) df[, get.var] Or, if you know your variables in the data.frame will be named sequentially df[, c(1, 2, x)] -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Lisa Sent: Tuesday, December 29, 2009 3:55 PM To: r-help@r-project.org Subject: Re: [R] Remove double quotation marks Thank you for your help. But here I just want to combine some vectors by column based on the numbers determined by other R script. For example, I have five vectors: v1 - c(0, 1, 0) v2 - c(1, 1, 0) v3 - c(2, 1, 2) v4 - c(2, 2, 1) v5 - c(0, 1, 1) If I am going to combine the first two vectors, and one more other vector determined by my other R script, say, vector 5. Then my R script is x - 5 cbind(v1, v2, paste(v, x, sep = )) The output is v1 v2 [1,] 0 1 v5 [2,] 1 1 v5 [3,] 0 0 v5 This is not what I want. I want to get this: v1 v2 v5 [1,] 0 1 0 [2,] 1 1 1 [3,] 0 0 1 Can you give me further suggestions or comments? Thanks a lot. Lisa Barry Rowlingson wrote: On Tue, Dec 29, 2009 at 6:31 PM, Lisa lisa...@gmail.com wrote: Thank you for your reply. But in the following case, cat() or print() doesn't work. data.frame(cbind(variable 1, variable 2, cat(paste(variable, x), \n))), where x is a random number generated by other R script. Lisa Yes, because you are Doing It Wrong. If you have data that is indexed by an integer, don't store it in variables called variable1, variable2 etc, because very soon you will be posting a message to R-help that is covered in the R FAQ... Store it in a list: v = list() v[[1]] = c(1,2,3,4,5) v[[2]] = c(4,5,6,7,8,9,9,9) then you can do v[[i]] for integer values of i. If you really really must get values of variable by name, perhaps because someone has given you a data file with variables called variable1 to variable99, then use the paste() construction together with the 'get' function: [ not tested, but should work ] v1=99 v2=102 i=2 get(paste(v,i,sep=)) [1] 102 Barry __ 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. -- View this message in context: http://n4.nabble.com/Remove-double-quotation-marks-tp990502p990586.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. === P Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S.News World Report (2009). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use\...{{dropped:13}} __ 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] Remove double quotation marks
Your script works well. Thank you very mcuh. Lisa Nutter, Benjamin wrote: It seems from your example that you're assuming all of the vectors have the same length. If this is the case, then a data.frame might be your friend. df - data.frame( v1 = c(0, 1, 0), v2 = c(1, 1, 0), v3 = c(2, 1, 2), v4 = c(2, 2, 1), v5 = c(0, 1, 1) ) x - 5 get.var - c(v1, v2, paste(v, x, sep=)) df[, get.var] Or, if you know your variables in the data.frame will be named sequentially df[, c(1, 2, x)] -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Lisa Sent: Tuesday, December 29, 2009 3:55 PM To: r-help@r-project.org Subject: Re: [R] Remove double quotation marks Thank you for your help. But here I just want to combine some vectors by column based on the numbers determined by other R script. For example, I have five vectors: v1 - c(0, 1, 0) v2 - c(1, 1, 0) v3 - c(2, 1, 2) v4 - c(2, 2, 1) v5 - c(0, 1, 1) If I am going to combine the first two vectors, and one more other vector determined by my other R script, say, vector 5. Then my R script is x - 5 cbind(v1, v2, paste(v, x, sep = )) The output is v1 v2 [1,] 0 1 v5 [2,] 1 1 v5 [3,] 0 0 v5 This is not what I want. I want to get this: v1 v2 v5 [1,] 0 1 0 [2,] 1 1 1 [3,] 0 0 1 Can you give me further suggestions or comments? Thanks a lot. Lisa Barry Rowlingson wrote: On Tue, Dec 29, 2009 at 6:31 PM, Lisa lisa...@gmail.com wrote: Thank you for your reply. But in the following case, cat() or print() doesn't work. data.frame(cbind(variable 1, variable 2, cat(paste(variable, x), \n))), where x is a random number generated by other R script. Lisa Yes, because you are Doing It Wrong. If you have data that is indexed by an integer, don't store it in variables called variable1, variable2 etc, because very soon you will be posting a message to R-help that is covered in the R FAQ... Store it in a list: v = list() v[[1]] = c(1,2,3,4,5) v[[2]] = c(4,5,6,7,8,9,9,9) then you can do v[[i]] for integer values of i. If you really really must get values of variable by name, perhaps because someone has given you a data file with variables called variable1 to variable99, then use the paste() construction together with the 'get' function: [ not tested, but should work ] v1=99 v2=102 i=2 get(paste(v,i,sep=)) [1] 102 Barry __ 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. -- View this message in context: http://n4.nabble.com/Remove-double-quotation-marks-tp990502p990586.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. === P Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S.News World Report (2009). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use\...{{dropped:13}} __ 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. -- View this message in context: http://n4.nabble.com/Remove-double-quotation-marks-tp990502p990599.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.