Last active
January 17, 2023 10:19
-
-
Save aadennis/0e9ffd2664afaf767c7998886c09a90d to your computer and use it in GitHub Desktop.
Adding observations to an existing dataframe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!require('PostcodesioR')) { | |
install.packages('PostcodesioR') | |
library('PostcodesioR') | |
} | |
postcodeSet.df <- postcode_lookup("EC1N 2HT") | |
mahSubset <- subset(postcodeSet.df, select=c(postcode, nhs_ha)) | |
# demo 1 row... | |
str(mahSubset) | |
# rbind is the bit that adds extra data rows to the data frame... | |
# (Note that this is not an efficient way, and we need to look at | |
# bulk equivalents of postcode_lookup if your data set gets large) | |
postcodeSet.df <- rbind(postcodeSet.df, postcode_lookup("G41 4NB")) | |
postcodeSet.df <- rbind(postcodeSet.df, postcode_lookup("PL1 1LE")) | |
postcodeSet.df <- rbind(postcodeSet.df, postcode_lookup("CV1 1FL")) | |
# demo total of 4 rows (1 original, plus 3 added...) | |
mahSubset2 <- subset(postcodeSet.df, select=c(postcode, nhs_ha)) | |
str(mahSubset2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment