Concerned_Citizen
Concerned_Citizen

Reputation: 6835

Read large csv file into R

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?

Upvotes: 1

Views: 683

Answers (1)

Wilmer E. Henao
Wilmer E. Henao

Reputation: 4302

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]

Upvotes: 3

Related Questions