R has 6 basic df types.
id | carat | cut | color | clarity | depth | table | price | x | y | z |
---|---|---|---|---|---|---|---|---|---|---|
1 | 0.23 | NA | E | SI2 | 61.5 | 55.0 | 326 | 3.95 | 3.98 | 2.43 |
2 | 0.21 | NA | E | SI1 | 59.8 | 61.0 | 326 | 3.89 | 3.84 | 2.31 |
3 | 0.23 | NA | E | VS1 | 56.9 | 65.0 | 327 | 4.05 | 4.07 | 2.31 |
4 | 0.29 | NA | I | VS2 | 62.4 | 58.0 | 334 | 4.20 | 4.23 | 2.63 |
5 | 0.31 | NA | J | SI2 | 63.3 | 58.0 | 335 | 4.34 | 4.35 | 2.75 |
6 | 0.24 | NA | J | VVS2 | 62.8 | 57.0 | 336 | 3.94 | 3.96 | 2.48 |
7 | 0.24 | NA | I | VVS1 | 62.3 | 57.0 | 336 | 3.95 | 3.98 | 2.47 |
library(tidyverse)
df <- diamonds
Using str() gets you that information plus additional such as the levels of your factors and the first few values of each variable.
str(diamonds$carat)
class(diamonds$carat)
df$depth <- as.numeric(df$depth)
df$cut <- as.factor(df$cut)
df$cut <- as.logical(df$cut)
df$cut <- as.character(df$cut)
df$date <- as.POSIXct(df$date, format="%Y-%m-%d %H:%M:%S", tz="UTC")
Description | Code |
---|---|
Year (4 Digits) | %Y |
Year (2 Digits) | %y |
Month (Full) | %B |
Month (Abbreviated) | %b OR %h |
Month (Decimal) | %m |
Week of Year (Start=Sunday) | %U |
Week of Year (Start=Monday) | %W |
Day of Year (Decimal) | %j |
Day of Month (Decimal) | %d |
Weekday (Full) | %A |
Weekday (Abbreviated) | %a |
Weekday (0=Sunday) | %w |
Hours (24 Hrs) | %H |
Hours (12 Hrs) | %I |
Minutes | %M |
Seconds | %S |
Locale-Specific Date & Time | %c |
Locale-Specific Date | %x |
Locale-Specific Time | %X |
Locale-Specific AM/PM | %p |
Offset from GMT | %z |
Time Zone | %Z |
format(Sys.time(), "%Y-%y")
format(Sys.time(), "%B-%b-%h-%m")
format(Sys.time(), "%U-%W")
format(Sys.time(), "%j-%d")
format(Sys.time(), "%A-%a-%w")
format(Sys.time(), "%H-%I-%M-%S")
format((Sys.Date()), format="%Y-%m-%d")
Sys.setenv(TZ = "UTC") # Sys.timezone()
https://stackoverflow.com/questions/21125222/determine-the-df-types-of-a-df-frames-columns