sqldf

Built Family nested tree parent / children relationship in R

余生颓废 提交于 2019-12-05 17:14:49
I am working on families trees : I have adapted Bob Horton's example based on sqldf https://www.r-bloggers.com/exploring-recursive-ctes-with-sqldf/ My data : person father Guillou Arthur NA Cleach Marc NA Guillou Eric Guillou Arthur Guillou Jacques Guillou Arthur Cleach Franck Cleach Marc Cleach Leo Cleach Marc Cleach Herbet Cleach Leo Cleach Adele Cleach Herbet Guillou Jean Guillou Eric Guillou Alan Guillou Eric My results, descendants ordered by levels of "Guillou Arthur" (top person without father) : name parent_name level Guillou Arthur NA 1 Guillou Eric Guillou Arthur 2 Guillou Jacques

Update function sqldf R Language

大城市里の小女人 提交于 2019-12-05 12:38:59
I have a problem with SQLdf. Although I am trying to update a table, it always gives NULL as an output. I red things about this problem but I cannot figure out how to solve it. My code is: fn$sqldf("update cons set V1='%$numbernew%' where V1=$'contact'") But after I check it to see if something has changed, all are the same as in the beginning. Any ideas would help. As Joran mentioned in a comment this question is an sqldf FAQ. In fact its sqldf FAQ #8 . As discussed there the problem is that you asked to update the table but never asked it to return the table. Also $'contract' should be '

SQL-like functionality in R

房东的猫 提交于 2019-12-05 01:37:15
I am used to writing data manipulation logic in SQL and now that I am learning R I find myself sometimes just wanting to do something that would be simple in SQL but I have to learn a bunch of stuff with R to do the same manipulation on an R data frame. Is there a simple work around? look at the package sqldf. http://code.google.com/p/sqldf/ It seems perfect for your needs. Josh Reich I'm also more comfortable with SQL, but when working with large data sets in R, my favourite manipulation tool is the data.table package. Unlike sqldf , which lets you write SQL in R, data.table lets you write R

call SQL function within R function

删除回忆录丶 提交于 2019-12-04 10:00:35
I am wondering if it is possible to call an SQL function within an R function? Say for example that I have this dummy data and SQL function written in Postgres 9.3 CREATE TABLE tbl ( id VARCHAR(2) PRIMARY KEY ,name TEXT ,year_born NUMERIC ,nationality TEXT ); INSERT INTO tbl(id, name, year_born, nationality) VALUES ('A1','Bill',2001,'American') ,('B1','Anna',1997,'Swedish') ,('A2','Bill',1991,'American') ,('B2','Anna',2004,'Swedish') ,('B3','Anna',1989,'Swedish') ,('A3','Bill',1995,'American'); CREATE FUNCTION retrieve_data(TEXT) RETURNS TABLE ( id VARCHAR(2), name TEXT, year_born NUMERIC,

R- sqldf error raw vs double

谁说我不能喝 提交于 2019-12-04 05:04:15
问题 I have a vector lims, with the limits of a score: [1] 0.000000 7.025894 9.871630 12.411131 15.155998 18.099176 21.431354 25.391163 30.616550 40.356630 I create a table to classify other clients with: lims[1]<- -0.00001 a<-data.frame(lims[2:10]) colnames(a)<-'maxSc' a<-rbind(a, 100) lims<-data.frame(lims) lims$maxSc<-a colnames(lims)<-c('minSc', 'maxSc') > class(lims) [1] "data.frame" So my result is: > lims minSc maxSc 1 -0.000010 7.025894 2 7.025894 9.871630 3 9.871630 12.411131 4 12.411131

How can I pass R variable into sqldf?

假装没事ソ 提交于 2019-12-03 18:05:51
问题 I have some query like this: sqldf("select TenScore from data where State_P = 'AndhraPradesh'") But I have "AndhraPradesh" in a variable stateValue . How can I use this variable in a select query in R to get the same result as above. Please show me the syntax. 回答1: You can use sprintf : sqldf(sprintf("select TenScore from data where State_P = '%s'", stateValue)) 回答2: See Example 5 on the sqldf GitHub page. Example 5. Insert Variables Here is an example of inserting evaluated variables into a

package sqldf in R

二次信任 提交于 2019-12-02 22:05:06
问题 Is it possible to add comments inside the string in sqldf? Something like: sqldf('select ProductID, count(distinct SalePrice) as num_regPz from MYDF where SalesFlag=0 # coded value to identify regular prizes group by ProductID') Here "# coded value to identify regular prizes" is meant as a comment, and not as a part of the select statement. 回答1: Comments in SQL use this format: /* Comment goes here */ If you change your code to the following then it should work sqldf('select ProductID, count

How can I extract the month using sqldf package

青春壹個敷衍的年華 提交于 2019-12-02 14:05:22
问题 I tried to get a view that is based on group by of date by using sqldf package and a month function but I got an error : Error in sqliteSendQuery(con, statement, bind.data) : error in statement: no such function: month Here is my query: s<-sqldf("select month(dateTime),sum(wolfs) group by dateTime") Attached is a toy data frame: df <- read.table(text = "dateTime birds wolfs snakes 2014-05-21 9 7 a 2014-04-28 8 4 b 2014-04-13 2 8 c 2014-03-12 2 3 a 2014-02-04 8 3 a 2014-02-29 1 2 a 2014-01-17

package sqldf in R

时间秒杀一切 提交于 2019-12-02 08:40:29
Is it possible to add comments inside the string in sqldf? Something like: sqldf('select ProductID, count(distinct SalePrice) as num_regPz from MYDF where SalesFlag=0 # coded value to identify regular prizes group by ProductID') Here "# coded value to identify regular prizes" is meant as a comment, and not as a part of the select statement. Comments in SQL use this format: /* Comment goes here */ If you change your code to the following then it should work sqldf('select ProductID, count(distinct SalePrice) as num_regPz from MYDF where SalesFlag=0 /* coded value to identify regular prizes */

R- sqldf error raw vs double

心不动则不痛 提交于 2019-12-02 04:53:16
I have a vector lims, with the limits of a score: [1] 0.000000 7.025894 9.871630 12.411131 15.155998 18.099176 21.431354 25.391163 30.616550 40.356630 I create a table to classify other clients with: lims[1]<- -0.00001 a<-data.frame(lims[2:10]) colnames(a)<-'maxSc' a<-rbind(a, 100) lims<-data.frame(lims) lims$maxSc<-a colnames(lims)<-c('minSc', 'maxSc') > class(lims) [1] "data.frame" So my result is: > lims minSc maxSc 1 -0.000010 7.025894 2 7.025894 9.871630 3 9.871630 12.411131 4 12.411131 15.155998 5 15.155998 18.099176 6 18.099176 21.431354 7 21.431354 25.391163 8 25.391163 30.616550 9 30