Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error no applicable method for 'select_' applied to an object of class "character"

Tags:

r

Here is my script (I try to: read csv -- rename all columns name -- select some of the columns and write the output as another csv)

but I get error for select function:

Error in UseMethod("select_") : no applicable method for 'select_' applied to an object of class "character"

Here is my code:

 Old_Data <-
 read.csv("K:/International/New Miestone.csv", stringsAsFactors = FALSE)
names(Old_Data) <-
    c("Enrol.Year",
    "VTAC.Course.Code",and so on)%>%

select(
"Enrol.Year", and so on)

write.csv(Old_data,path,.....)

Strangely, I used to import data from txt file and set names for headers, then select, then write csv, never has such problem

like image 305
Baron Avatar asked Aug 30 '25 16:08

Baron


1 Answers

library(dplyr)

#Read the csv
Old_Data <- read.csv("K:/International/New Miestone.csv", stringsAsFactors = FALSE)

#Rename all the columns and select required columns
New_Data <- Old_Data %>%
             rename_all(funs(c("Enrol.Year", "VTAC.Course.Code",...))) %>%
             select(Enrol.Year,  VTAC.Course.Code, ...)

#Write the csv
write.csv(New_Data,path)
like image 50
Ronak Shah Avatar answered Sep 02 '25 04:09

Ronak Shah