robjectr-rownames

Convert object list to obtain rownames R


I am having trouble extracting rownames from an object. When I type in rownames(object), I obtain "null", but if I type in object, I obtain the matrix of information. If it helps, when I type in class(object), it tells me that it is a list. What I am looking for is a method to obtain the row names on the side. Thanks!

>

        alpha84 alpha91 alpha98 alpha105 alpha112 alpha119
YBR088C    1.08    0.27    0.04    -0.51    -0.80    -0.89
YDL003W    0.62   -0.01   -0.36    -0.04    -0.55    -0.55
YDR097C    0.64    0.18   -0.05     0.03    -0.76    -0.66
YDR507C    0.53    0.13    0.07     0.14    -0.56    -0.41
YER070W    0.73    0.20    0.00     0.11    -0.53    -0.72
YER095W    0.28   -0.05   -0.11    -0.13    -0.87    -0.90
YER111C    0.37   -0.19   -0.11    -0.54    -0.34    -0.47
YGR189C    0.81    0.12    0.15    -0.39    -0.60    -1.20
YKL045W    0.46   -0.27   -0.10    -0.23    -0.42    -1.21
YLR183C    0.96    0.14    0.28    -0.17    -0.14    -0.68
YML027W    0.50   -0.01    0.11    -0.33    -0.44    -0.94
YMR179W    0.42    0.04   -0.40    -0.47    -0.12    -0.61
YNL300W    0.79    0.33    0.54    -0.09    -0.31    -1.01
YOR074C    0.73    0.09   -0.27    -0.22    -0.62    -0.80
YPL163C    1.61    0.84    0.82    -0.09    -0.48    -0.97
YPL256C    1.10    0.56    0.18    -0.32    -0.38    -1.04

structure(list(4 = structure(list(alpha0 = c(-1.15, -1.22, -0.72, -1.76, -1.46, -0.57, -1.21, -0.32, -0.8, -1.7, -1.72, -1.3, -1.24, -1.14, -2.42, -1.41), alpha7 = c(-0.86, -0.74, -0.85, -0.34, -0.76, 0.42, -0.26, -0.65, 0.01, -1.46, -0.66, 0.07, -0.78, -0.31, -2.15, -0.69), alpha14 = c(1.21, 1.34, 0.54, 0.18, 1.08, 1.03, 1.36, 0.87, 0.86, 0.93, 1.73, 0.98, 0.31, 0.57, 0.66, 1.39 ), alpha21 = c(1.62, 1.5, 1.04, 1.07, 1.5, 1.35, 1.37, 1.1, 0.84, 1.12, 1.29, 1.12, 1.46, 1.08, 1.98, 1.98), alpha28 = c(1.12, 0.63, 0.84, 0.37, 0.74, 0.64, 0.54, 1.17, 0.51, 0.91, 0.51, 0.13, 1.11, 1.17, 1.55, 0.74), alpha35 = c(0.16, 0.29, 0.24, 0.32, 0.47, 0.42, 0.18, 0.44, 0.14, 0.11, 0.28, 0.19, 0.62, 0.57, 0.78, 0.21), alpha42 = c(-0.44, -0.55, -0.64, -0.5, -0.7, -0.4, -0.85, 0.37, -0.4, 0, 0.23, -0.58, 0.07, 0.31, 0.14, -0.36), alpha49 = c(-0.93, -0.65, -0.83, -0.25, -0.68, -0.9, -0.82, -0.93, -0.64, -0.73, -0.55, -0.63, -0.23, -0.74, -0.94, -1.32), alpha56 = c(-1.23, -0.76, -0.36, -0.48, -1.03, -0.73, -0.75, -1.45, -0.8, -0.9, -0.97, -0.9, -0.58, -0.68, -1.03, -1.5), alpha63 = c(-0.62, -0.88, -0.7, -0.25, -0.55, -0.47, 0.07, -0.57, 0.41, -0.46, -0.48, 0.09, -1.01, -0.1, -1.5, -1.07), alpha70 = c(0.62, 0.69, 0.99, 0.79, 0.35, 0.2, 0.89, 0.15, 0.88, 0.85, 0.57, 0.54, -0.24, -0.38, -0.03, 0.35), alpha77 = c(1.3, 1.25, 1.08, 0.97, 1.24, 0.78, 0.78, 0.92, 0.75, 0.93, 0.88, 1.44, 0.23, 0.75, 1.25, 1.57), alpha84 = c(1.08, 0.62, 0.64, 0.53, 0.73, 0.28, 0.37, 0.81, 0.46, 0.96, 0.5, 0.42, 0.79, 0.73, 1.61, 1.1), alpha91 = c(0.27, -0.01, 0.18, 0.13, 0.2, -0.05, -0.19, 0.12, -0.27, 0.14, -0.01, 0.04, 0.33, 0.09, 0.84, 0.56), alpha98 = c(0.04, -0.36, -0.05, 0.07, 0, -0.11, -0.11, 0.15, -0.1, 0.28, 0.11, -0.4, 0.54, -0.27, 0.82, 0.18), alpha105 = c(-0.51, -0.04, 0.03, 0.14, 0.11, -0.13, -0.54, -0.39, -0.23, -0.17, -0.33, -0.47, -0.09, -0.22, -0.09, -0.32), alpha112 = c(-0.8, -0.55, -0.76, -0.56, -0.53, -0.87, -0.34, -0.6, -0.42, -0.14, -0.44, -0.12, -0.31, -0.62, -0.48, -0.38), alpha119 = c(-0.89, -0.55, -0.66, -0.41, -0.72, -0.9, -0.47, -1.2, -1.21, -0.68, -0.94, -0.61, -1.01, -0.8, -0.97, -1.04)), .Names = c("alpha0", "alpha7", "alpha14", "alpha21", "alpha28", "alpha35", "alpha42", "alpha49", "alpha56", "alpha63", "alpha70", "alpha77", "alpha84", "alpha91", "alpha98", "alpha105", "alpha112", "alpha119"), row.names = c("YBR088C", "YDL003W", "YDR097C", "YDR507C", "YER070W", "YER095W", "YER111C", "YGR189C", "YKL045W", "YLR183C", "YML027W", "YMR179W", "YNL300W", "YOR074C", "YPL163C", "YPL256C"), class = "data.frame")), .Names = "4")


Solution

  • You have a list of one element. This single element is a data.frame.

    If you are after the rownames from this object, then index the list appropriately

    rownames(object[[1]])
    ## [1] "YBR088C" "YDL003W" "YDR097C" "YDR507C" "YER070W" "YER095W" "YER111C" "YGR189C" "YKL045W" "YLR183C" "YML027W"
    ## [12] "YMR179W" "YNL300W" "YOR074C" "YPL163C" "YPL256C"
    

    For a more general list of data.frames

    # get rownames from all data.frames in a list
    lapply(object, rownames)
    

    If you want a data.frame, not a list containing a data.frame then you could simply assign the results from the first element to a separate element

    object.df <- object[[1]]
    

    If it is a list of data.frames, it probably is more idiomatically R to keep it in the list, and use lapply to work on each element.