0

I have a dataset having variables from Q1 to Q60. They are characters from 0 to 10. I want to convert them to numeric variables. I am a new user of R.

How can I do that in a loop?

r2evans
  • 141,215
  • 6
  • 77
  • 149
Hui G
  • 1
  • Welcome to stackoverflow! Your question is not completely clear. Please follow the link below to learn how to ask a questions correctly https://stackoverflow.com/help/how-to-ask – Yuriy Tsarkov Sep 03 '19 at 21:10
  • [How to ask a good question](https://stackoverflow.com/help/how-to-ask) & [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) & [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) & Please include some data: [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – Trenton McKinney Sep 04 '19 at 03:01
  • `isQ <- grepl("^Q", colnames(x)); x[,isQ] <- lapply(x[,isQ], as.numeric)` – r2evans Sep 04 '19 at 05:23
  • `library(tidyverse); df %>% gather(question, value) %>% mutate(value = as.numeric(value))` – Jon Spring Sep 04 '19 at 06:36

0 Answers0