Error: unexpected symbol in:

Hi, I tried to convert the whole of my dataset to numeric using this code line:
New <- class(as.numeric(exam[ , ~.]) to enable me do a PCA on the dataset but the error I get is
Error: unexpected symbol in:

Please how do I resolve it as I am a bit new in R.

you will find it most convenient to learn and use the tidyverse package.

it will give you access to syntax as follows:
New <- exam %>% mutate_all(as.numeric)

reproducible example :

#example dataframe
exam <- data.frame(a=c("1","2","3"),
                  b=c("4","5","6"),stringsAsFactors = FALSE)

New <- exam %>% mutate_all(as.numeric)

Hi thanks but I tried to load the package and library and here' the error:

Error: package or namespace load failed for ‘tidyverse’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
namespace ‘modelr’ 0.1.4 is being loaded, but >= 0.1.5 is required
In addition: Warning message:
package ‘tidyverse’ was built under R version 3.6.2

any new package you have never used before would need to be installed on your system.
if you use rstudio and have a script loaded, the IDE should be asking you towards the top whether to install.
otherwise, you can install from your console (i.e. leave it out of your script).

1 Like

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