R从自定义字符串中删除空格

[英]R remove spaces from custom string


I am trying to pass a list of stocks to a SQL query, sequentially. To do this, I pass a custom string to the sqlQuery command.

我试图按顺序将库存列表传递给SQL查询。为此,我将自定义字符串传递给sqlQuery命令。

I build the string as follows:

我按如下方式构建字符串:

my.stocks <- c('BIL','BTI')
a <- "SELECT TRADE_DATE_TIME,PRICE  FROM MYDATA where TRADE_DATE_TIME > '2013-01-01' and INSTR_CODE = "
b <- my.stocks[1]
c <-  "order by TRADE_DATE_TIME asc"
my.string <- paste(a,"'",b,"'",c)

my problem is that in the custom string, there are spaces between the quotation marks and variable b. How do I remove these spaces?

我的问题是在自定义字符串中,引号和变量b之间有空格。如何删除这些空格?

1 个解决方案

#1


1  

Use the sep argument to paste:

使用sep参数粘贴:

my.string <- paste(a,"'",b,"'",c, sep="")

You'll also have to add a space at the start of the c string:

您还必须在c字符串的开头添加一个空格:

c <-  " order by TRADE_DATE_TIME asc"

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/01/10/eb05b866f00908a67293da5a538ff393.html



 
  © 2014-2022 ITdaan.com 联系我们: