I have a large CSV file and I only want to import select certain rows if it. First I create the indices of the rows that will be imported then I wish to pass the names of these rows to sqldf and return the full records for specified rows.
#create the random rows ids that will be sampled
library(dplyr)
#range for the values
index<-c(1:20)
index<-as.data.frame(as.matrix(index))
#number of values to be returned
number<-5
ids<-sample_n(index,number)
#sample the data
library(sqldf)
#filepath
f<-file("/Users/.../filename.csv")
#select data
df<-sqldf("select * from f")
How to import a selection of rows from a CSV file by specifying the row numbers?