rtypesnumericcolumn-types

Changing Columns 22-300 from double (or other type) into numeric


I have a huge dataset and some columns are text. Upon importing the Excel file and using preview, I can manually change the first 50 columns to numeric, if this applies. But, there are still 250 more columns I need to change to numeric. How would I use R code to change all columns from column 22 through column 300 to numeric?


Solution

  • One way:

    mydf[22:300] <- lapply(mydf[22:300], as.numeric)