Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import last 100 rows using read.csv() in R

Tags:

import

r

csv

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?

like image 924
Prasun Velayudhan Avatar asked Aug 30 '13 06:08

Prasun Velayudhan


People also ask

How to read a CSV file in R?

How to read a CSV file in R? In this section you will learn how to import a CSV file in R with the read.csv and read.csv2 functions. You can see the basic syntax of the functions with the most common arguments in the following code block. For additional details remember to type ?read.csv or ?read.csv2.

How to read CSV file and select specific rows and columns?

In this article, we are going to see how to read CSV file and select specific rows and columns in R Programming Language. To import a CSV file into the R environment we need to use a pre-defined function called read.csv (). Pass filename.csv as a parameter within quotations.

How to import CSV file in R with comma separated values?

CSV (Comma Separated Values) file contains list of data which separated from comma (,).To import csv file R uses read.csv () or read.csv2 () function. Both function are almost same as to the read.table () function.

How to load a CSV file in R with default arguments?

The following table summarizes the three main default arguments: “.” In order to load a CSV file in R with the default arguments, you can pass the file as string to the corresponding function.


1 Answers

The package R.utils has a function called countLines(). You could do:

l2keep <- 10
nL <- countLines("your.csv")
df <- read.csv("your.csv", header=FALSE, skip=nL-l2keep)
like image 125
lauratboyer Avatar answered Sep 28 '22 21:09

lauratboyer