0

I am new using R, and I have a problem when reading data. I am reading a .csv file:

table<- read.table("/Users/.../data.plants.csv", header=FALSE, sep=";")

The table has the format:

      V1              V2                    V3         V4         V5     V6        V7        V8

1 nutrient light microsatellite_length genotype_A genotype_B height leaf_type leaf_size

2 rich bright 4 AA Bb 48.5 rough 10.43

3 rich bright 2 Aa Bb 47 smooth 6.54

....(continues)

I want to just select one column, the column that has leaf size. I am doing it like this:

x<-subset(table,select=c(V8)) 

It has a problem, it also selects the header ("leaf_size") and I want just the numeric values. How can I select just the column numeric values?

2
  • 1
    Use header=TRUE in your read.table call. Or just use read.csv as it defaults to this. Commented Feb 13, 2012 at 17:06
  • I'll put it as an answer then, so people can see that its solved. Commented Feb 13, 2012 at 17:29

2 Answers 2

1

Use header=TRUE in your read.table call. Or just use read.csv as it defaults to this.

plants <- read.csv("/Users/.../data.plants.csv")
Sign up to request clarification or add additional context in comments.

Comments

0

To add to the first answer, by default, read.csv results in strings being classified as factors. If you do not want this (and generally, you don't), one uses:

read.table('plants.csv', stringsAsFactors=FALSE, sep=';') -> plants
plants[,6]

will then give you the sixth column as strings. I'll assume you want it as numbers, given by as.numeric(plants[,6]). Hope that helps!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.