Regarding the format of the data, if they are as factor
, the ideal is to correct this in reading the data. Numeric values read as factors can occur for any of the following reasons:
-
Your table is transposed: For R, the data must have variables (if any, characteristics) in the columns, and observations (animals) in the rows. In this way, all columns will have the same data type (number, text, logical, date, etc.).
-
There is content that is not part of the data, such as comment at the beginning or end of the data.
-
You did not read the data correctly. The stringsAsFactors
argument is useful for preventing texts from seeing factors (but should not be necessary for numbers), and you may also need to use skip
or row.names
. We can only help you better if you provide the original data, or a representative sample of them.
To separate only one characteristic (column), you can do it in several ways, but the simplest is to use the $
operator, as follows:
animais$peso
This will return all the observations of the weight column, in the form of a vector.
If you can not solve the import problem, you can convert factors to numbers as follows:
animais$peso <- as.numeric(as.character(animais$peso))
Or, a little more efficient:
animais$peso <- as.numeric(levels(animais$peso))[animais$peso]