Regarding the format of the data, if they are as factor
, the ideal is to correct this in the reading of the data. Numerical values read as factors may occur for any of the following reasons:
Your table is transposed: For R, the data must have variables (in your case, characteristics) in the columns, and observations (animals) in the rows. Thus, all columns will have the same type of data (number, text, logic, date, etc).
There is content that is not part of the data, such as comment at the beginning or end of the data.
You have not read the data correctly. The argument stringsAsFactors
is useful to prevent texts from seeing factors (but should not be required for numbers), and it may also be necessary to use skip
or row.names
. We can only help you better if you provide the original data, or a representative sample of it.
To separate only one feature (column), you can do it in several ways, but the simplest is to use the operator $
, as follows:
animais$peso
This will return all observations of the weight column, in the form of a vector.
If you cannot 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]
I was left with a little doubt, about your question, you want to filter your data and transform the objects or? Maybe you can provide an example of your data.
– Jean