Reputation: 6835
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
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