How do I make smaller tables from a data.frame in R?

4

I have a table in the data frame, with 100 animals, but with 500 observations of various characteristics. as I do to have subtables, with only the animals and the characteristic x, being q he should show tds the 500 observations of this characteristic X. Detail animals is like factor with 100 levels, and observations are as levels tbem, I wish he had only as normal numbers, contains dot (3.2 4.2)

type animal 1 1.1 2.0 1.0 0.2 1.7 .... (500 times) animal 2

Thank you.

    
asked by anonymous 21.01.2016 / 14:45

1 answer

3

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]
    
21.01.2016 / 21:44