Reputation: 59
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
Upvotes: 4
Views: 35946
Reputation: 389047
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)
Upvotes: 3