Q:

Access data in a file by column in R?

If I have this file: 
symbol,length,pval
a,5.196415406,0.02376069902
b,4.269985245,0.01861663475
c,3.591334103,0.01391749469

I wanna read the file and access it by column, like data$symbol or data$length: 
here is my code: 
res <- read.csv(file="myfile.csv", header=TRUE, sep=",")
data <- as.matrix(res) 

but data$symbol doesn't work, 
any help, 
Thanks 

A:

You converted your object to a matrix and so will need to extract accordingly.  You can refer to the column names as follows:
data[, 'symbol']
data[, 'length']
data[, 'pval']

