I am new to R and Rstudio and have been struggling with a problem for three days, HELP!
I can successfully query postgres sql db and create into a dataframe, but any additional manipulation of that dataframe fails. I always seem to get the same error "object not found"
Estimate1 <- dbGetQuery(conep, "select substring(notes, 7, 6) as jobnum, a.entrydate, a.estimatorid, a.estimatenumber, a.deliverydate, a.customerid, a. notes, a.prospectname, a.customerprospectname, a.status, a.description, a.enteredby, a.highestestimateversion, b.price from estimate a left outer join estimatepricesummary b on a.estimateid=b.estimateid where entrydate>'2018-12-31' and highestestimateversion !=false and status='2' and notes like '%#%' order by entrydate")
jobnum <- (as.numeric(gsub("([0-9]+).*$", "\\1", jobnum )))
Estimate1.df$jobnum <- jobnum
Error in gsub("([0-9]+).*$", "\\1", jobnum) : object 'jobnum' not found
There are easier ways of doing everything in your snippet, but we'll leave those for another time. Reply if this doesn't get you over the immediate problem.
Thanks for replying, unfortunately that doesn't seem to be working either. Perhaps I should describe my intention.
I have the query, but I need to extract a job number from the column called notes, yes they put the job number in a notes field. The job number is an alphanumeric string of 5 or 6 digits preceded by "#". I have tried to use the str_extract here, but as I stated before none of the functions I attempt recognize the column reference from the initial query data frame.
Estimate1 <- dbGetQuery(conep, "select a.entrydate, a.estimatorid, a.estimatenumber, a.deliverydate, a.customerid, a. notes, a.prospectname, a.customerprospectname, a.status, a.description, a.enteredby, a.highestestimateversion, b.price from estimate a left outer join estimatepricesummary b on a.estimateid=b.estimateid where entrydate>'2018-12-31' and highestestimateversion !=false and status='2' and notes like '%#%' order by entrydate")
job_int<- str_extract(notes,"\#")
You are trying to reference the column "notes" that is part of a dataframe, notes doesn't exist in memory by its own, it is part of Estimate1 so you have to reference it as Estimate1$notes