0

I am working in RStudio with R version 2.15.1. I saved an Excel file in CSV file and imported that to R (with the read.csv() function). When I do dim(file), I got:

[1] 4920 23 

But when I tried to retrieve the very first element with file[1:1], I got the entire first column! Why is that?

lmo
  • 37,904
  • 9
  • 56
  • 69
Concerned_Citizen
  • 6,548
  • 18
  • 57
  • 75
  • 5
    use a comma `file[1,1]`. `file[1:1]` tells R to take the first list (data frames are a collection of lists) and `:` says basically 'go until' the last list, also 1 in your case, so it returns all from 1 until 1, which would just be (all of) column 1. – rawr Jan 10 '14 at 19:13
  • Try fread(): ```require(data.table) DT <- fread("test.csv")``` http://stackoverflow.com/questions/1727772/quickly-reading-very-large-tables-as-dataframes-in-r – marbel Jan 10 '14 at 19:26
  • what is the real dim()? – marbel Jan 10 '14 at 19:28

1 Answers1

3

you need comas for each dimension. So

file[i, j]

is the element on the i^{th} row and j^{th} column. If you want the whole first row, the proper way to do it is to type

file[1, ]

What you did is useful in selecting several rows. So if you type

file[c(1:4),]

will select the first 4 columns and so on. In your particular case what you want to type is:

file[1, 1]
Wilmer E. Henao
  • 4,094
  • 2
  • 31
  • 39