我不知道我的问题是否能代表我的需要
我有这段代码:
i<-0 j<-0
for(i in 0:m){ j<- j+1 neighborhood <- fn$sqldf("SELECT object2
FROM distance WHERE object1=('$j') AND neighbor=TRUE UNION SELECT
object1 FROM distance WHERE object2=('$j') AND neighbor=TRUE ")
for (neighbor in neighborhood){
fn$sqldf(" INSERT INTO neighborhoods(object,neighborhood)
VALUES ('$neighbor','$neighbor')")
邻域的结果是(8,10,11)
我想在表邻居中获得结果,如:
(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 8.10, 8.11, 9.9,
等
但我总是在postgresqlExecStatement(conn,statement,...)中得到此错误:
RS-DBI驱动程序:(无法检索结果:错误:整数的输入语法无效:“c(8,10,11)” 第1行:......到邻里(对象,邻居)价值观('8','c(8,10,... ^ )
我发现,如何通过像这样的循环得到我想要的结果
i&lt; - 0 j&lt; - 1 for(i in 0:m){core&lt; - fn $ sqldf(“SELECT core FROM core_point WHERE gid =('$ j')“)if(core = FALSE){
fn $ sqldf(“插入邻域(对象,邻域)值('$ j','$ j'”)j&lt; -j + 1} if(core == TRUE){ 邻域&lt; - fn $ sqldf(“SELECT object2 FROM distance WHERE object1 =('$ j')AND neighbor = TRUE UNION SELECT object1 FROM 距离WHERE object2 =('$ j')AND neighbor = TRUE“)a <-fn$sqldf("select totalneighborhoods from core_point where gid='$j'") a <- as.numeric(a) for(k in 1:a){ o<- neighborhood[k,1] fn$sqldf(" INSERT INTO neighborhoods(object,neighborhood) VALUES ('$j','$o')") k<- k+1 } j<- j+1 } }
但我认为它会获得这个过程,任何想法? *对不起,如果我的英语不好
答案 0 :(得分:0)
试试这个:
a <- 8
b <- c(8,9,10)
paste(a,b,sep=".") # If you need string output
as.numeric(paste(a,b,sep=".")) # If you need numeric output