Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ptz-communal
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DREAL Pays de la Loire
Centre de Services de la Donnée
Requêtes serveur CGDD
ptz-communal
Commits
c0ddd482
Commit
c0ddd482
authored
9 months ago
by
Daniel.Kalioudjoglou
Browse files
Options
Downloads
Patches
Plain Diff
suite script chargement ptz
parent
5e00afa8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
chargement_ptz.R
+58
-10
58 additions, 10 deletions
chargement_ptz.R
with
58 additions
and
10 deletions
chargement_ptz.R
+
58
−
10
View file @
c0ddd482
library
(
readr
)
library
(
tidyr
)
library
(
dplyr
)
library
(
COGiter
)
library
(
stringr
)
library
(
lubridate
)
millesime
=
2023
# ma_region = "52"
# Départements de ma région
# mes_departements <- list_dep_in_reg(ma-region)
# path <- paste("/nfs/data/partage-PTZ-EPTZ/PTZ-EPTZ/BASE_PTZ_DHUP_",millesime,"_DREAL.csv")
BASE_PTZ_DHUP
<-
read_delim
(
paste0
(
"/nfs/data/partage-PTZ-EPTZ/PTZ-EPTZ/BASE_PTZ_DHUP_"
,
millesime
,
"_DREAL.csv"
),
delim
=
";"
,
escape_double
=
FALSE
,
trim_ws
=
TRUE
)
ptz
<-
BASE_PTZ_DHUP
%>%
base
<-
BASE_PTZ_DHUP
%>%
# cpfl = code postal , cins = code insee, cdco = code commune déclaré
# lcom = libéllé commune, timm = type logement (1 = individuel, 2 = collectif)
# tope = type d'opération :
...
...
@@ -17,20 +25,60 @@ ptz <- BASE_PTZ_DHUP %>%
# 5 : Transformation de locaux non destinés à l’habitation en logement
# 6 : Levée d’option en location-accession, pour le 1er locataire
# 7 : Acquisition d’un logement avec travaux de remise à neuf
select
(
cpfl
,
cins
,
cdco
,
lcom
,
timm
,
tope
)
%>%
select
(
cpfl
,
cins
,
cdco
,
lcom
,
timm
,
tope
,
an
)
%>%
mutate
(
type_logt
=
case_when
(
timm
==
1
~
"individuel"
,
timm
==
2
~
"collectif"
,
TRUE
~
"non_renseigne"
),
TRUE
~
"
type_
non_renseigne"
),
etat_logt
=
case_when
(
tope
%in%
c
(
1
,
2
,
3
)
~
"neuf"
,
tope
%in%
c
(
4
,
5
,
6
,
7
)
~
"ancien"
,
TRUE
~
"non_renseigne"
)
TRUE
~
"
etat_
non_renseigne"
)
)
%>%
rename
(
code_insee
=
cins
)
%>%
group_by
(
code_insee
,
type_logt
,
etat_logt
)
%>%
summarise
(
nb_logt
=
length
(
code_insee
))
%>%
ungroup
()
arrange
(
code_insee
)
ptz_detail
<-
base
%>%
group_by
(
an
,
code_insee
,
type_logt
,
etat_logt
)
%>%
summarise
(
valeur
=
length
(
code_insee
))
%>%
ungroup
()
%>%
mutate
(
variable
=
paste0
(
"ptz-"
,
type_logt
,
"-"
,
etat_logt
))
%>%
select
(
-
type_logt
,
-
etat_logt
)
ptz_total
<-
base
%>%
group_by
(
an
,
code_insee
)
%>%
summarise
(
valeur
=
length
(
code_insee
))
%>%
ungroup
()
%>%
mutate
(
variable
=
"ptz-total"
)
ptz_type
<-
base
%>%
group_by
(
an
,
code_insee
,
type_logt
)
%>%
summarise
(
valeur
=
length
(
code_insee
))
%>%
ungroup
()
%>%
mutate
(
variable
=
paste0
(
"ptz-"
,
type_logt
))
%>%
select
(
-
type_logt
)
ptz_etat
<-
base
%>%
group_by
(
an
,
code_insee
,
etat_logt
)
%>%
summarise
(
valeur
=
length
(
code_insee
))
%>%
ungroup
()
%>%
mutate
(
variable
=
paste0
(
"ptz-"
,
etat_logt
))
%>%
select
(
-
etat_logt
)
# recapitulatif
ptz
<-
bind_rows
(
ptz_detail
,
ptz_etat
,
ptz_type
,
ptz_total
)
%>%
select
(
depcom
=
code_insee
,
an
,
variable
,
valeur
)
%>%
complete
(
an
,
depcom
,
variable
)
%>%
mutate_all
(
funs
(
ifelse
(
is.na
(
.
),
0
,
.
)))
%>%
mutate
(
date
=
make_date
(
an
,
12
,
31
))
%>%
select
(
-
an
)
%>%
pivot_wider
(
names_from
=
variable
,
values_from
=
valeur
)
# rm(ptz_detail,ptz_etat,ptz_type,ptz_total)
# cogification
cogifiee_ptz
<-
cogifier
(
ptz
%>%
rename
(
DEPCOM
=
depcom
))
%>%
mutate_if
(
is.factor
,
as.character
)
#controle
nb_lgts
<-
ptz
%>%
pull
(
nb_logt
)
%>%
sum
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment