Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

Select columns when reading in files with st_read

$
0
0

I am trying to read 39 json files into a common sf dataset in R.

Here is the method I've been trying:

path <- "~/directory" 
file.names <- as.list(dir(path, pattern='.json', full.names=T)) 
geodata <- do.call(rbind, lapply(file.names, st_read))

The problem is in the last line: rbind cannot work because the files have different numbers of columns. However, they all have three columns in common, and which I care about: MOVEMENT_ID, DISPLAY_NAME and geometry. How could I select only these three columns when running st_read?

I've tried running geodata<-do.call(rbind, lapply(file.names, st_read,select=c('MOVEMENT_ID', 'DISPLAY_NAME', 'geometry'))) but, in this case, st_read does not seem to recognise the geometry column (error: 'no simple features geometry column pressent'). I've also tried to use fread in place of st_read but this doesn't work as fread is not adapted to spatial data.


Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>