Dataframe reads a column of strings as a column of lists

I have the following datafraame column:
df$HtmlString <- lapply(df$HtmlCode, set_lists_to_chars)

set_lists_to_chars <- function(x) {
    if(!is.null(x)) {
    y <- paste(unlist(x), sep='', collapse=' NEWELEMENT ')
    } else {
    y <- x 

The elements of the column HtmlString are obviously made of characters, because when I print type of any its element, I get "character"


But whenever I look at the type of the column in the dataframe, I get 'list' type:


Why does this happen?

Because lapply() returns a list. Can’t check now, but try

lapply(df$HtmlCode, set_lists_to_chars) |> unlist(x = _)

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.