R - Column-type changes from "numeric" to “unknown” when there is only one row

1.6k Views Asked by At

When I do a filter on a dataframe and the resulting dataframe has only one row, all the column-types that were "numeric" becomes "unknown".

Here is an example that you should be able to reproduce:

    df_test_1 <- data.frame(c(1))
    colnames(df_test_1) <- c("Column_1")
    df_test_1$Column_1 <- as.numeric(as.character(df_test_1$Column_1))

    df_test_2 <- data.frame(c(1, 2))
    colnames(df_test_2) <- c("Column_1")
    df_test_2$Column_1 <- as.numeric(as.character(df_test_2$Column_1))

The column-type of df_test_2 is numeric but df_test_1 is unknown

I am using R 3.5.3 with Rstudio 1.0.143

1

There are 1 best solutions below

3
Rodrigo Orellana On

Update R.

Both are numeric using class function in R 3.6.1.