Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201919

Convert column/variable to row names for multiple lists in R with sapply

$
0
0

I am trying to convert a column to row names for each list of an object using sapply.

tibble::column_to_rownames() is not an option because it "always returns a data frame".

For a single variable (class sf, data.frame), using the base function:

rownames(polygon_nyc_listings[[1]]) <- polygon_nyc_listings[[1]]$zipcode

It works perfectly without changing the class: sf, data.frame.

So I am trying to repeat for each list the function above without success:

test <- sapply(polygon_nyc_listings,
                 function(x){rownames(x) <- x$zipcode},
                 simplify = FALSE, USE.NAMES = TRUE)

I instead get an object with zipcode lists class character.

Does someone know how to proceed?


Viewing all articles
Browse latest Browse all 201919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>