0

I dont know if my question can represent what I need

I have this code :

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')")

The result of neighborhood is (8,10,11)

I want to get result in table neighborhoods like:

(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 8.10, 8.11, 9.9, etc

but I always get this Error in postgresqlExecStatement(conn, statement, ...) :

RS-DBI driver: (could not Retrieve the result : ERROR: invalid input syntax for integer: "c(8, 10, 11)" LINE 1: ...TO neighborhoods(object,neighborhood) VALUES ('8','c(8, 10, ... ^ )

I just find out, how to get the result I want with some loop like this

i <- 0 j <- 1 for (i in 0:m){ core <- fn$sqldf("SELECT core FROM core_point WHERE gid=('$j')") if (core = FALSE){
fn$sqldf("insert into neighborhoods(object, neighborhood) values ('$j', '$j'") j<-j+1 } if (core ==TRUE){ neighborhood <- fn$sqldf("SELECT object2 FROM distance WHERE object1=('$j') AND neighbor=TRUE UNION SELECT object1 FROM distance 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   } }

But I think it will gain the process, any idea? *sorry if my english is not good

Nadina
  • 185
  • 1
  • 1
  • 8
  • help me please :( I just want to know how to merge the number if i have a<- 8 and b<- 8, 9, 10 then the result became c< 8.8, 8.9, 8.10 – Nadina Apr 18 '14 at 02:05
  • 1
    Read this about creating a reproducible example: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – G. Grothendieck Apr 18 '14 at 02:25

1 Answers1

0

Try this:

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
Shambho
  • 3,250
  • 1
  • 24
  • 37