Skip to content

Instantly share code, notes, and snippets.

@messefor
Last active November 6, 2016 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save messefor/9db068f2f32dbae6f9a3a21da7e0b5aa to your computer and use it in GitHub Desktop.
Save messefor/9db068f2f32dbae6f9a3a21da7e0b5aa to your computer and use it in GitHub Desktop.
how to convert each column data type in data.frame
# set function with which convert data into named vector
col.type.f <- c(vane=as.factor,
prefecture=as.factor,
date=as.Date,
time=as.factor,
ts=as.POSIXct)
# convert data type
for (col in names(col.type.f)) {
f.conv <- col.type.f[col][[1]]
dt[col] <- f.conv(dt[,col])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment