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 联系我们: