Skip to main content
edited tags
Link
Jan
  • 11.9k
  • 7
  • 24
  • 35
Source Link

The data is changed after fwrite and fread

I am trying to store several columns of the data, and then merge them with the other data when necessary. However, the data could only be merged with other data when I created it at the start, and it fails after fwrite and fread the data.

region <- climatebound_rast |> as.data.table(xy = TRUE) fwrite(region, "region.csv") region2 <- fread("region.csv", stringsAsFactors = TRUE) all.equal(region,region2) [1] TRUE TEST <- raster_to_table[Variable=="npp"&Model=="DLEM", 1:4] # 1. Merge raster data with region data merged_region <- merge(TEST, region, all.x = TRUE) |> drop_na(region) merged_region Key: <x, y> x y Model Variable region <num> <num> <char> <char> <fctr> 1: 87.99277 49.0312 DLEM npp MNG 2: 88.49277 48.5312 DLEM npp MNG 3: 88.49277 49.0312 DLEM npp MNG 4: 88.99277 48.0312 DLEM npp MNG 5: 88.99277 48.5312 DLEM npp MNG --- 5846: 161.49277 68.5312 DLEM npp RUS 5847: 161.99277 68.5312 DLEM npp RUS 5848: 161.99277 69.0312 DLEM npp RUS 5849: 162.49277 68.5312 DLEM npp RUS 5850: 162.49277 69.0312 DLEM npp RUS merged_region2 <- merge(TEST, region2, all.x = TRUE) |> drop_na(region) merged_region2 Key: <x, y> Empty data.table (0 rows and 5 cols): x,y,Model,Variable,region