Append data in sqlite3 c++ - sqlite

i have a table in sqlite like:
e.g
Columns
|a |b |c |d |e |
|5 |6 |4 |3 |6 |
columns a - e holds an integer
now i need to add number to some columns
for example add 3 to column 'c' and now c will hold 7.
how can i do it?

I think this could be done with a simple update query like this:
UPDATE <table> SET c = c + 1;

Related

subset rows between two rows containing specific values?

I have multiple data frames with the generic layout below. The strings of text vary in length from a few words to multiple sentences. The title strings on each data frame all vary slightly but they all share a word in common (for example, all of the TitleBs on each data frame share the word “code” in common and all TitleCs share the word “write” in common).
|element|NumbID|String |
|-—————-|-————-|-———————-|
|header |1 |TitleA |
|para |2 |TxtStrng |
|header |3 |TitleB |
|header |4 |Subtit1 |
|para |5 |TxtStrng |
|header |6 |Subtit2 |
|para |7 |TxtStrng |
|header |8 |TitleC |
I am trying to figure out how to write a code that can be used on all the data frames and will allow me to extract all the rows starting at TitleB and just before TitleC, as in the example below.
|element|NumbID|String |
|:————-:|:———-:| :————--:|
|header |3 |TitleB |
|header |4 |Subtit1 |
|para |5 |TxtStrng |
|header |6 |Subtit2 |
|para |7 |TxtStrng |
I thought maybe I could use subset() in some way to do this but I’m really struggling to figure out how to make it work.
So, you need a way to identify TitleB and TitleC strings. From you're description, I'll use grepl("code", String) for TitleB and grepl("write", String) for TitleC.
Then we need to identify rows where a TitleB has already occurred but a TitleC hasn't: we can use cumsum for this to generate a cumulative count of occurrences:
result = subset(
your_data,
cumsum(grepl("code", String)) > 0 &
cumsum(grepl("write", String)) == 0
)
If you need more help, please make your example more reproducible, preferably using dput() to share a copy/pasteable version of the data in valid R syntax.

Implement a Photoshop Photo Filter on CSS

I want to recreate the result of Photoshop Photo Filters on css but not really sure which mix-blend-mode to use and how.
I know this is a fairly trivial task, but I still need a little hint.
Ideally, I would like to combine these two filters into one. Here are the filter details and some test colors
R E S U L T C O L O R S
+----------+ +----------+
| | | |
| f0f4e7 | | eac91a |
| | | |
+----------+ +----------+
^
Photo Filter 2 Yellow (f9e31c)
15% no preserve luminosity
^
Photo Filter 1 Underwater (00c2b1)
8% no preserve luminosity
^
I N I T I A L C O L O R S
+----------+ +----------+
| | | |
| ffffff | | ebca1c |
| | | |
+----------+ +----------+

SQLite Versioning. Is it possible to use EXCEPT to show differences between rows where only one column changes?

I'm quite new to SQLite and I'm trying to use an EXCEPT statement in order to compare two tables with very similar data. The data comes from a CSV file I download daily, and within the file new rows are added and deleted, and old rows can have one or more columns change each day. I'm trying to find a way to select rows that have had a column's data change, when I am unable to predict which column's data will change.
Say for example I have:
TABLE contracts:
|ID|Description|Name|Contract Type|
|1 |Plumbing |Bob |Paper |
|2 |Cooking |Ryan|Paper |
|3 |Driving |Eric|Paper |
|4 |Dancing |Emma|Paper |
and:
TABLE updated_contracts:
|ID|Description|Name|Contract Type|
|1 |Hiking |Bob |Paper |
|2 |Cooking |Ryan|Paper |
|3 |Driving |Eric|Paper |
|4 |Dancing |Emma|Digital |
I'd like it to return:
|1 |Hiking |Bob |Paper |
|4 |Dancing |Emma|Digital |
because contract 1 has changed the description and contract 4 has changed the contract type.
Is it possible to do this in SQLite?
One way to do it is with a LEFT join of updated_contracts to contracts where the matching rows are filtered out:
select uc.*
from updated_contracts uc left join contracts c
using(id, Description, Name, `Contract Type`)
where c.id is null
EXCEPT can also be used like this:
select * from updated_contracts
except
select * from contracts
This will work only if the tables have the same number of columns and its advantage is that it compares null values in columns and returns true if they are both null.
See the demo.
Results:
| ID | Description | Name | Contract Type |
| --- | ----------- | ---- | ------------- |
| 1 | Hiking | Bob | Paper |
| 4 | Dancing | Emma | Digital |

Proxy for Excel's split cell in R

Apologies in advance if anyone finds this to be a duplicate to a question answered before. I haven't found anything so here it is:
I have a 3x3 contingency table I made in RStudio (I am specifying this as a data frame below but I can also produce this as as.matrix, if that'll work better):
mat.s=data.frame("WT(H)"=11,"DEL(H)"=2)
mat.s[2,1]=13
mat.s[2,2]=500369
row.names(mat.s)=c("DEL(T)", "WT(T)")
mat.s=cbind(mat.s, Total=rowSums(mat.s))
mat.s=rbind(mat.s, Total=colSums(mat.s))
which looks like:
kable(mat.s)
| | WT.H.| DEL.H.| Total|
|:------|-----:|------:|------:|
|DEL(T) | 11| 2| 13|
|WT(T) | 13| 500369| 500382|
|Total | 24| 500371| 500395|
However, if I wanted to split a cell in this table (like you can do in Excel) into two, how would I do that? So I'd like to get something like the following when I render the document with kable:
| | WT.H.| DEL.H.| Total|
|:------|-----:|------:|------:|
|DEL(T) | S D | 2| 13|
| | 8 3 | | |
|WT(T) | 13| 500369| 500382|
|Total | 24| 500371| 500395|
So that when I want to calculate something from this table, I can call the split 8 or 3. Sorry if this is something very simple and easy to do! Still learning. Thanks!

SAS data reorgnization- linking information from one column to another

I have a dataset with a village name, market, churches, and hospitals. Markets, churches and hospitals are not given names directly; rather, they are listed by village, so that they can be directly linked to the village name. Coordinates are only listed by village. I need to reorganize a dataset in SAS, so that GPS coordinates for villages are linked to their respective markets, churches, and hospitals.
Here's a better visualization for what I'm trying to do:
Transform this dataset:
Long |Lat |Village|Market |Church
----------------------------------------
X(A) |Y(A) | A |A |A
X(B) |Y(B) | B |B |B
X(C) |Y(C) | C |A |A
X(D) |Y(D) | D |A |D
X(E) |Y(E) | E |B |B
X(F) |Y(F) | F |F |F
X(G) |Y(G) | G |F |F
X(H) |Y(H) | H |H |F
To something that looks like this, with newly created columns for Market and Church coordinates (based off of the original village coordinates):
Long|Lat |Village|Market|Market_Long|Market_Lat |Church|Church_Long|Church_Lat
-------------------------------------------------------------------------------
X(A)|Y(A) |A |A |X(A) |Y(A) |A |X(A) |Y(A)
X(B)|Y(B) |B |B |X(B) |Y(B) |B |X(B) |Y(B)
X(C)|Y(C) |C |A |X(A) |Y(A) |A |X(A) |Y(A)
X(D)|Y(D) |D |A |X(A) |Y(A) |D |X(D) |Y(D)
X(E)|Y(E) |E |B |X(B) |Y(B) |B |X(B) |Y(B)
X(F)|Y(F) |F |F |X(F) |Y(F) |F |X(F) |Y(F)
X(G)|Y(G) |G |F |X(F) |Y(F) |F |X(F) |Y(F)
X(H)|Y(H) |H |H |X(H) |Y(H) |F |X(F) |Y(F)
I know the formatting is a little strange here, so here are a couple of images of these sample tables:
Original Table:
Desired Table:
Thanks for any light you can shed on this!
As was commented, the answer seems as trivial as just defining them asnew variables. As you are going to be defining the new variables anyway, you can use the length statement to set the order you want them to appear in the dataset.
data old;
input lon $ lat $ village $ market $ church $ hosp $;
Datalines;
X(A) Y(A) A A A B
X(B) Y(B) B B B B
X(C) Y(C) C A A D
X(D) Y(D) D A D D
X(E) Y(E) E B B B
;
run;
data new;
length lon lat village market market_lon market_lat Church church_lon church_lat
hosp hosp_lon hosp_lat $ 100;
set old;
market_lon = lon;
market_lat = lat;
church_lon = lon;
church_lat = lat;
hosp_lon = lon;
hosp_lat = lat;
run;
This will work for a simple case but if there are many more variables than just market, church and hosp you may be interested in using macros and a %do loop to iterate over a list of the varnames instead of manually defining the new variables.
Great article for macro %do: http://blogs.sas.com/content/sastraining/2015/01/30/sas-authors-tip-getting-the-macro-language-to-perform-a-do-loop-over-a-list-of-values/

Resources