[datatable-help] Data type unintentionally converting on data table on join

sant santosh.srinivas at gmail.com
Wed Apr 6 14:17:04 CEST 2011


Hello all,

Sorry if this is obvious but once of my variable(datetime) is
automatically changing with a join operation. I am not sure if this
expected and I don't want that to happen
I have three datasets the dputs are given at the end of the mail.

The problem I am facing is shown as follows (pls help):

#d1$datetime is num here
str(d1)

#Doing a join
tmp <- J(d1,d2,d3)
str(tmp)
#tmp$datetime is int here

#Why is this change?

###############################################################################################################################################

FIRST DATA SET

> dput(d1)
structure(list(ticker = c("OPTIDX-NIFTY-28APR2011-5100-CE", "OPTIDX-
NIFTY-28APR2011-5100-CE",
"OPTIDX-NIFTY-28APR2011-5100-CE", "OPTIDX-NIFTY-28APR2011-5100-CE",
"OPTIDX-NIFTY-28APR2011-5100-CE", "OPTIDX-NIFTY-28APR2011-5100-CE"
), datetime = c(20110405.092102, 20110405.092538, 20110405.093458,
20110405.101124, 20110405.102041, 20110405.103659), der_typ =
c("OPTIDX",
"OPTIDX", "OPTIDX", "OPTIDX", "OPTIDX", "OPTIDX"), opt_typ = c("CE",
"CE", "CE", "CE", "CE", "CE"), underlying = c("NIFTY", "NIFTY",
"NIFTY", "NIFTY", "NIFTY", "NIFTY"), strike = c("5100", "5100",
"5100", "5100", "5100", "5100"), expiry_dt = c("2011-04-28",
"2011-04-28", "2011-04-28", "2011-04-28", "2011-04-28", "2011-04-28"
), Id = structure(1:6, .Label = c("OPTIDX-NIFTY-28APR2011-5100-
CE-20110405.092102",
"OPTIDX-NIFTY-28APR2011-5100-CE-20110405.092538", "OPTIDX-
NIFTY-28APR2011-5100-CE-20110405.093458",
"OPTIDX-NIFTY-28APR2011-5100-CE-20110405.101124", "OPTIDX-
NIFTY-28APR2011-5100-CE-20110405.102041",
"OPTIDX-NIFTY-28APR2011-5100-CE-20110405.103659"), class =
"factor")), .Names = c("ticker",
"datetime", "der_typ", "opt_typ", "underlying", "strike",
"expiry_dt",
"Id"), row.names = c(NA, -6L), class = c("data.table", "data.frame"
))
>

SECOND DATA SET

> dput(d2)
structure(list(Id = structure(1:6, .Label = c("OPTIDX-
NIFTY-28APR2011-5100-CE-20110405.092102",
"OPTIDX-NIFTY-28APR2011-5100-CE-20110405.092538", "OPTIDX-
NIFTY-28APR2011-5100-CE-20110405.093458",
"OPTIDX-NIFTY-28APR2011-5100-CE-20110405.101124", "OPTIDX-
NIFTY-28APR2011-5100-CE-20110405.102041",
"OPTIDX-NIFTY-28APR2011-5100-CE-20110405.103659"), class = "factor"),
    price = c(826, 820, 819, 830.2, 825.45, 835.15)), .Names =
c("Id",
"price"), row.names = c(NA, -6L), class = c("data.table", "data.frame"
))
>

THIRD DATA SET

> dput(d3)
structure(list(Id = structure(1:6, .Label = c("OPTIDX-
NIFTY-28APR2011-5100-CE-20110405.092102",
"OPTIDX-NIFTY-28APR2011-5100-CE-20110405.092538", "OPTIDX-
NIFTY-28APR2011-5100-CE-20110405.093458",
"OPTIDX-NIFTY-28APR2011-5100-CE-20110405.101124", "OPTIDX-
NIFTY-28APR2011-5100-CE-20110405.102041",
"OPTIDX-NIFTY-28APR2011-5100-CE-20110405.103659"), class = "factor"),
    volume = c(50, 50, 200, 50, 100, 50)), .Names = c("Id", "volume"
), row.names = c(NA, -6L), class = c("data.table", "data.frame"
))
>



> sessionInfo()
R version 2.12.1 (2010-12-16)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United
Kingdom.1252    LC_MONETARY=English_United Kingdom.1252
LC_NUMERIC=C                            LC_TIME=English_United Kingdom.
1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods
base

other attached packages:
[1] data.table_1.5.3

loaded via a namespace (and not attached):
[1] tools_2.12.1
>


More information about the datatable-help mailing list