Hi I've a huge file and i want to import only the last 100 rows from that file. How can we do that using read.csv() or any alternative?
相关问题
- R - Quantstart: Testing Strategy on Multiple Equit
- Using predict with svyglm
- Reshape matrix by rows
- Extract P-Values from Dunnett Test into a Table by
- split data frame into two by column value [duplica
相关文章
- How to convert summary output to a data frame?
- How to plot smoother curves in R
- Paste all possible diagonals of an n*n matrix or d
- ess-rdired: I get this error “no ESS process is as
- How to read local csv file in client side javascri
- How to use doMC under Windows or alternative paral
- dyLimit for limited time in Dygraphs
- Saving state of Shiny app to be restored later
You could use the
nrows
andskip
arguments inread.csv
. E.g. if you have a file with 10000 rows and you would only like to import the last 100 rows you could try this:But if it is speed you want, you're probably better off with the solutions given by @Ananda Mahto and @ktdrv
If you are on a *nix system, you are better off using the
tail -n 100
command to take the last 100 rows. Anything implemented in R would be slower and potentially much slower is your file is truly huge.If you are using Windows, you may want to take a look at this SO question.
The quick and dirty way that works for me - use
fread
to read large files while settingselect = 1
so that only the first column is read. Then usefread
again to read data from the desired rows.Fread
is much faster thanread.csv
or other similar variants. More onfread
vsread.csv
here: Reason behind speed of fread in data.table package in RRead file, use tail function a<-read.csv('c:/..') tail(a,100L)
give appropriate skip parameter in read.csv()
Improvement on @lauratboyer's answer if you want to include headers too: