0

In R, I'm trying to get a cell value from a read.csv object. But this is what I get:

a<- tail(sp.csv, n=1L)
a$V1
[1] 5042951
54 Levels: 11054 1156785) 1157947) 1159014) 1166898) 1174855) ... src,trg,sp_len,hops

Where, sp.csv is the read.csv object variable. Even if I try variants like: a$V1[[1]] or a[['V1']][1] what am I doing wrong, any suggestions? What I need is the values from V1 and V2.

sAguinaga
  • 638
  • 13
  • 31
  • 2
    Can you describe what exactly isn't working? The output seems correct to me. The reasons you have levels there is because `V1` is a `factor`. – David Arenburg Jun 16 '15 at 09:46
  • I think I figured my error, I did this: `sp.csv <-data.frame(read.csv(file, header=F, sep="\t"))` if I remove the conversion to a data.frame, I can access the individual cell value. I need to read about `factor` in R. – sAguinaga Jun 16 '15 at 09:58
  • @sAguinaga You can use `stringsAsFactors=FALSE` in the `read.csv`, to get the non-numeric column as character column. It seems to me that it is a numeric column, but there are some elements in that column that make it non-numeric. Check your dataset to find any non-numeric elements and then specify `na.strings=` in the read.csv – akrun Jun 16 '15 at 10:01
  • Use `stringsAsFactors = FALSE` with `data.frame` or `read.csv` – Pierre L Jun 16 '15 at 10:03

0 Answers0