Please note that this is a cross post.
Originally posted here: r - Read chunkwise and compute 2 variables - Stack Overflow
I wish to read from MySQL database chunkwise, create TWO summary variables and write chunkwise to another table. Here is how I think we may do this seperately as follows(I have not tried the code):
library(RMySQL)
library(chunked)
library(dplyr)
connection <- dbConnect(dbDriver("MySQL"),host = "myhost",
db="mydb",user="myuser",password="mypass")
# Computing the number of members in a household.
tbl(connection,"table1") %>%
read_chunkwise() %>%
select(hid,year) %>%
group_by(hid,year) %>%
summarise(Total_members= n()) %>%
write_chunkwise("table2")
# Extracting the age of the head of household, I know that for
# each hid, year there will be only one member with
# relation_with_hoh == "hoh"
tbl(connection,"table1") %>%
read_chunkwise() %>%
select(hid,year,relation_with_hoh,age) %>%
filter(relation_with_hoh=="hoh") %>%
mutate(hoh_age = age) %>%
select(hid,year,hoh_age) %>%
write_chunkwise("table2")
My question is: How do I these 2 together ?