Nicolas

2 minute read

Big dataset

(Ok, not so big)

df <- tibble::tribble(
   ~ID,             ~city,     ~lat,    ~lon,
  1172,           "Zaria", 11.11128,   7.7227,
  1173,            "Oslo", 59.91273, 10.74609,
  1174, "Masqat (Muscat)", 23.61387,  58.5922,
  1175,      "Bahawalpur",     29.4, 71.68333,
  1181,"Islamabad",33.70351,73.059373,
  1194,"Rawalpindi",33.6,73.0666667

  )
df
## # A tibble: 6 x 4
##      ID city              lat   lon
##   <dbl> <chr>           <dbl> <dbl>
## 1  1172 Zaria            11.1  7.72
## 2  1173 Oslo             59.9 10.7 
## 3  1174 Masqat (Muscat)  23.6 58.6 
## 4  1175 Bahawalpur       29.4 71.7 
## 5  1181 Islamabad        33.7 73.1 
## 6  1194 Rawalpindi       33.6 73.1

Create smaller dataset

small_df <- df[1:3,]
small_df
## # A tibble: 3 x 4
##      ID city              lat   lon
##   <dbl> <chr>           <dbl> <dbl>
## 1  1172 Zaria            11.1  7.72
## 2  1173 Oslo             59.9 10.7 
## 3  1174 Masqat (Muscat)  23.6 58.6

Serialize it with dput()

dput(small_df)
## structure(list(ID = c(1172, 1173, 1174), city = c("Zaria", "Oslo", 
## "Masqat (Muscat)"), lat = c(11.11128, 59.91273, 23.61387), lon = c(7.7227, 
## 10.74609, 58.5922)), row.names = c(NA, -3L), class = c("tbl_df", 
## "tbl", "data.frame"))

Rebuild the small dataset with structure()

By copy-pasting the output of dput()

small_df2 <- structure(list(ID = c(1172, 1173, 1174), city = c("Zaria", "Oslo", 
"Masqat (Muscat)"), lat = c(11.11128, 59.91273, 23.61387), lon = c(7.7227, 
10.74609, 58.5922)), row.names = c(NA, -3L), class = c("tbl_df", 
"tbl", "data.frame"))

small_df2
## # A tibble: 3 x 4
##      ID city              lat   lon
##   <dbl> <chr>           <dbl> <dbl>
## 1  1172 Zaria            11.1  7.72
## 2  1173 Oslo             59.9 10.7 
## 3  1174 Masqat (Muscat)  23.6 58.6
  • Category
  • R