-8

I need to find number of rows & columns of a text file? I have used a function to find it. eg: I have a text file 'test' with 20 rows & 10 columns. How do I find the number of rows & columns of the file 'test'?

  • 1
    I think you just want the `dim()` function. It would be more clear if you provided a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and described exactly what the desired output is. – MrFlick Aug 17 '16 at 15:23
  • 1
    Did you try searching for this first? I typed "number of rows for text file in R" into google and [the first link](https://www.r-bloggers.com/easy-way-of-determining-number-of-linesrecords-in-a-given-large-file-using-r/) had a very nice answer. – Barker Aug 17 '16 at 16:12
  • 1
    Thank you Guys. New to R :) – Beginne'R' Sep 14 '16 at 21:12

1 Answers1

1

You need to make the example reproducible.

I took the question to mean "making your own function" which would be solved by the following example

lengthFunc <- function(filePath){

df<-read.csv(filePath)

df<- data.frame(df)
return(c(nrow(df), ncol(df))
}


testRead <- lengthFunc(filePath)

Numrow<- testRead[1]
Numcols <- testRead[2]

Using MrFlick's comment you could do the following

dataFrame <- data.frame(read.csv(pathName))

rows would be given by

dim(dataFrame)[1]

columns:

dim(dataFrame)[2]
DataTx
  • 1,839
  • 3
  • 26
  • 49