sqldf

Update a column in df2 by matching patterns in columns in df1 & df2 using R

空扰寡人 提交于 2019-12-13 07:35:58
问题 I have 2 data frames like this TEAM <- c("PE","PE","MPI","TDT","HPT","ATD") CODE <- c(NA,"F","A","H","G","D") df1 <- data.frame(TEAM,CODE) CODE <- c(NA,"F100","A234","D664","H435","G123","A666","D345","G324",NA) TEAM <- c(NA,NA,NA,NA,NA,NA,NA,NA,NA,NA) df2 <- data.frame(CODE,TEAM) I am trying to update the TEAM in df2 by matching the first letter in code column in df1 with the code column in df2 My desired output for df2 CODE TEAM 1 NA PE 2 F100 PE 3 A234 MPI 4 D664 ATD 5 H435 TDT 6 G123 HPT

R sprintf in sqldf's like

杀马特。学长 韩版系。学妹 提交于 2019-12-13 02:27:52
问题 I would like to do a looping query in R using sqldf to that select all non-NULL X.1 variable with date "11/12/2015" and at 9AM. Example : StartDate X.1 11/12/2015 09:14 A 11/12/2015 09:36 11/12/2015 09:54 A The date is in variable that generated from other query nullob<-0 dayminnull<-as.numeric(sqldf("SELECT substr(Min(StartDate),1,03)as hari from testes")) # this produce "11/12/2015" for (i in 1 : 12){ dday<-mdy(dayminnull)+days(i) #go to next day sqlsql <- sprintf("SELECT count([X.1]) FROM

Error in rsqlite_send_query

懵懂的女人 提交于 2019-12-13 00:39:45
问题 I have the below table names lco_act_data head(lco_act_data) X SMZ_N ACRES HH2030 ENR2030 RE2030 OFF2030 OTH2030 TOT2030 1 1 1603.5114 11325 1706 407 1368 1162 3085 2 2 907.2274 2079 1062 332 1028 1190 2654 3 3 758.8701 1407 1447 60 1949 1315 3829 4 4 170.1726 868 0 76 737 128 964 5 5 820.4855 5338 304 198 1343 1597 3249 6 6 1596.5201 4584 3272 346 1351 1411 3195 When I'm trying to alter the table using sqldf function below its throwing me the below error and I can't seem to understand why.

R sqldf renaming a field in a select statement

人盡茶涼 提交于 2019-12-12 20:56:56
问题 Edited the question to be clearer as requested. Note that the inputs are provided in reproducible form in the Note at the end. I am using sqldf to join two datasets in R The code returns a dataset with the with the original column names, ignoring the "as" in the select statement. output_1 <- sqldf("SELECT a.MRN, a.TestDate, b.TestDate as Date2 from a inner join b on a.MRN=b.MRN order by a.MRN, a.TestDate") giving: > sapply(output_1,colnames) $MRN NULL $TestDate NULL $TestDate NULL > head

Unable to install sqldf on Linux

久未见 提交于 2019-12-12 17:41:57
问题 I'm running R version 2.14.1 on Linux. When I try to install sqldf with install.packages(sqldf, dependencies=TRUE) I get the following errors: (these errors result in running the command from the terminal as with the use of the Rcmdr UI) open log here I can't seem to find someone with a similar problem. If I run the install command on a Windows PC, it installs without any problems. 回答1: You error log has the line: In file included from RS-PQescape.c:7:0: RS-PostgreSQL.h:23:26: fatal error:

ideas to avoid hitting memory limit when using dbWriteTable to save an R data table inside a SQLite database

▼魔方 西西 提交于 2019-12-12 16:17:37
问题 a data frame that's small enough to be loaded into R still occasionally hits the memory-limit ceiling during a dbWriteTable call if it was near the maximum amount of RAM available. i'm wondering if there's any better solution than reading the table into RAM in chunks like the code below? i'm trying to write code that will work on older computers, so i'm using the windows 32-bit version of R to re-create these memory errors.. # this example will only work on a computer with at least 3GB of RAM

Difference in dates using sqldf in R

*爱你&永不变心* 提交于 2019-12-12 03:29:43
问题 I have two columns in a data frame where I need to calculate the difference in time. The data is the local PD data from open data of cities. One column is below TimeDispatch 01/01/2011 12:00:37 AM TimeArrive 01/01/2011 12:21:31 AM Also the TimeArrival as a few missing values as every dispatch does not need the cops to arrive. I am trying to find the difference using sqldf in R but it says this error Error in sqliteSendQuery(conn, statement, bind.data) : RAW() can only be applied to a 'raw',

SQLite in R - error in result_create(conn@ptr, statement) : near “)”

孤者浪人 提交于 2019-12-11 15:18:48
问题 Sorry for the basic question, but I am trying to run the following code with sqldf function in R, but every time it shows "Error in result_create(conn@ptr, statement) : near ')': syntax error" and I can't find exactly where the error is. I tried to indent/format in different ways but the error indication to "near ')'" persists all the time. It seems all parenthesis are fine. Code: sqldf(" SELECT Cia_2, Nombre_cia_2, N_orden_2, Tipo_orden_2, N_linea_2, N_direc_2, Nombre_alfa_2, Fecha_orden_2,

sqldf missing value where TRUE/FALSE needed

允我心安 提交于 2019-12-11 11:14:03
问题 In sqldf_0.4-7.1 I get: Error in if (.allows_extensions(db)) { : missing value where TRUE/FALSE needed Where is the package that fixes the bug? My error is the same as the one generated by: sqldf("select * from warpbreaks limit 6") I downloaded sqldf v0.4-7.1 from CRAN but with newer source does not help some 8 hours later. 回答1: Problem is with that sqldf version. Fixed version should be already on the cran so you will need to update your sqldf package. Download file sqldf_0.4-9.tar.gz and in

Read only n-th column of a text file which has no header with R and sqldf

佐手、 提交于 2019-12-11 06:22:26
问题 I have a similiar problem like this question: selecting every Nth column in using SQLDF or read.csv.sql I want to read some columns of large files (table of 150rows, >500,000 columns, space separated, filled with numeric data and only a 32 bit system available). This file has no header, therefore the code in the thread above didn't work and I decided to write a new post. Do you have an idea to solve this problem? I thought about something like that, but any results with fread or read.table