不明白为什么不能同时检测或删除时间戳列中的所有NA。 尽管我通过查询删除了所有NA,但NA仍在我的数据中,但无法被查询检测到,但会显示在数据查看器中。有关详细信息,请参见以下内容:
在列时间戳中,我从列visit_start_time_gmt
(这里是Unix时间戳)创建了一个日期时间:
data_1<-cbind(data_1,anytime(as.numeric(as.character(data_1$visit_start_time_gmt))))
发生了一些NA,在以下位置将其删除:
data_1<-data_1[!is.na(data_1$timestamp),]
而且,按预期,结果为0:
nrow(data_1[is.na(data_1$timestamp),])
我想知道,以下查询仍然会导致不适用:
max(data_1$timestamp)
因此,我确实在数据查看器中进行了查看,但仍然惊讶地看到4个NA:
在以下行中:
我完全困惑,无法按行号删除此行(尝试以这种方式删除后,NA仍在我的数据中):
data_1<-data_1[-c(788748,94812,94819,94825),]
只能通过我自己的列index_id删除
data_1<-data_1[!data_1$index_id %in% c(788748,94812,94819,94825),]
是什么原因导致此尴尬的问题?如何才能以正确的方式检测并删除实际上所有的NA?
您可以在此处创建数据(包括列时间戳中的4个不可检测的NA):
head(dput(data_1[c(1:10),]))
structure(list(index_id = c(94812L, 94814L, 94815L, 94816L, 94817L,
94818L, 94819L, 94821L, 94822L, 94823L, 94824L, 94825L, 94827L,
94828L, 94829L, 94830L, 94831L, 94832L, 94833L, 94834L, 94835L,
94836L, 94837L, 94838L, 94839L, 94840L, 94841L, 94842L, 94843L,
94844L, 94845L, 94846L, 94847L, 94848L, 94849L, 94850L, 94851L,
94852L, 94853L, 94854L, 94855L, 94856L, 94857L, 94858L, 94859L,
94860L, 94861L, 94862L, 94863L, 94864L, 94865L), campaign = c("",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", ""), exclude_hit = c("0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0", "0", "0", "0"), first_hit_page_url = c("http://www.samsung.com/de/",
"http://www.samsung.com/de/", "http://www.samsung.com/de/", "http://www.samsung.com/de/",
"http://www.samsung.com/de/", "http://www.samsung.com/de/", "http://www.samsung.com/de/",
"http://www.samsung.com/de/", "http://www.samsung.com/de/", "http://www.samsung.com/de/",
"http://www.samsung.com/de/", "http://www.samsung.com/de/", "http://www.samsung.com/de/",
"http://www.samsung.com/de/", "http://www.samsung.com/de/", "http://www.samsung.com/de/",
"http://www.samsung.com/de/", "http://www.samsung.com/de/", "http://www.samsung.com/de/",
"http://www.samsung.com/de/", "http://www.samsung.com/de/", "http://www.samsung.com/de/",
"http://www.samsung.com/de/", "http://www.samsung.com/de/", "http://www.samsung.com/de/",
"http://www.samsung.com/de/mobile-content-page/", "http://www.samsung.com/de/mobile-content-page/",
"http://www.samsung.com/de/mobile-content-page/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/consumer/mobile-devices/accessories/power/EP-PG920IBEGWW",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/mobile-content-page/"
), first_hit_pagename = c("de:home", "de:home", "de:home", "de:home",
"de:home", "de:home", "de:home", "de:home", "de:home", "de:home",
"de:home", "de:home", "de:home", "de:home", "de:home", "de:home",
"de:home", "de:home", "de:home", "de:home", "de:home", "de:home",
"de:home", "de:home", "de:home", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "de:contents", "de:contents", "de:contents",
"de:contents", "de:contents", "de:contents", "de:contents", "de:contents",
"de:contents", "de:contents", "de:contents", "de:contents", "de:contents",
"de:contents", "de:contents", "de:contents", "de:contents", "de:contents",
"de:contents", "de:contents", "de:consumer:mobile devices:accessories:power:ep-pg920ibegww",
"de:contents", "de:mobile-content-page"), first_hit_ref_domain = c("",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", ""), first_hit_ref_type = c("1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "6", "6", "6", "6", "6", "6", "6",
"6", "6", "6", "6", "6", "6", "6", "6", "6", "6", "6", "6", "6",
"6", "6", "6", "6", "6", "6"), first_hit_referrer = c("http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"http://www.samsung.com/de/contents/", "http://www.samsung.com/de/contents/",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", ""), first_hit_time_gmt = c("1515600363",
"1515600363", "1515600363", "1515600363", "1515600363", "1515600363",
"1515600363", "1515600363", "1515600363", "1515600363", "1515600363",
"1515600363", "1515600363", "1515600363", "1515600363", "1515600363",
"1515600363", "1515600363", "1515600363", "1515600363", "1515600363",
"1515600363", "1515600363", "1515600363", "1515600363", "1525596576",
"1525596576", "1525596576", "1463949764", "1463954663", "1463974801",
"1463987199", "1464000142", "1464036391", "1464123965", "1464124564",
"1464132646", "1464136256", "1464136256", "1464170611", "1464191265",
"1464191265", "1464201356", "1464207203", "1464207203", "1464207203",
"1464212475", "1464212475", "1464212493", "1464212984", "1521765893"
), hit_source = c("1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1"), post_campaign = c("", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", ""), post_cust_hit_time_gmt = c("",
"1525737195", "1525737206", "1525737301", "1525737305", "1525737309",
"", "1525737331", "1525737346", "1525737358", "1525737388", "",
"1525737397", "1525737398", "1525737412", "1525737424", "1525737434",
"1525737448", "1525737521", "1525737526", "1525737534", "1525737557",
"1525737561", "1525737565", "1525737579", "1525736201", "1525736229",
"1525736426", "1525736763", "1525737360", "1525736174", "1525736723",
"1525736207", "1525736839", "1525737132", "1525736460", "1525737437",
"1525737070", "1525737322", "1525736704", "1525737233", "1525737237",
"1525737179", "1525736066", "1525736117", "1525736374", "1525735974",
"1525736045", "1525737342", "1525735841", "1525736055"), post_page_url = c("",
"http://www.samsung.com/de/support/newsalert/101154", "", "http://www.samsung.com/de/support/newsalert?filter=alert",
"", "http://www.samsung.com/de/support/newsalert?filter=alert",
"", "http://www.samsung.com/de/support/newsalert/100844", "",
"http://www.samsung.com/de/support/smart-simulator", "http://www.samsung.com/de/support/newsalert?filter=alert",
"", "http://www.samsung.com/de/support/newsalert/100844", "",
"", "", "http://www.samsung.com/de/support/smart-simulator",
"", "", "http://www.samsung.com/de/support/newsalert/100811",
"", "http://www.samsung.com/de/support/newsalert?filter=alert",
"http://www.samsung.com/de/support/smartswitch", "http://www.samsung.com/de/mobile-content-page",
"", "http://www.samsung.com/de/mobile-content-page", "http://www.samsung.com/de/mobile-content-page",
"http://www.samsung.com/de/mobile-content-page", "http://www.samsung.com/de/mobile-content-page",
"http://www.samsung.com/de/mobile-content-page", "http://www.samsung.com/de/mobile-content-page",
"http://www.samsung.com/de/mobile-content-page", "http://www.samsung.com/de/mobile-content-page",
"http://www.samsung.com/de/mobile-content-page", "http://www.samsung.com/de/mobile-content-page",
"http://www.samsung.com/de/mobile-content-page", "http://www.samsung.com/de/mobile-content-page",
"http://www.samsung.com/de/mobile-content-page", "http://www.samsung.com/de/mobile-content-page",
"http://www.samsung.com/de", "http://www.samsung.com/de", "",
"http://www.samsung.com/de/mobile-content-page", "http://www.samsung.com/de/mobile-content-page",
"http://www.samsung.com/de/mobile-content-page", "http://www.samsung.com/de/mobile-content-page",
"http://www.samsung.com/de/mobile-content-page", "http://www.samsung.com/de/mobile-content-page",
"http://www.samsung.com/de/mobile-content-page", "http://www.samsung.com/de/mobile-content-page",
"http://www.samsung.com/de/mobile-content-page"), post_pagename = c("",
"de:support:newsalert:101154", "", "de:support:newsalert", "",
"de:support:newsalert", "", "de:support:newsalert:100844", "",
"de:support:smart-simulator", "de:support:newsalert", "", "de:support:newsalert:100844",
"", "", "", "de:support:smart-simulator", "", "", "de:support:newsalert:100811",
"", "de:support:newsalert", "de:support:smartswitch", "de:mobile-content-page",
"", "de:mobile-content-page", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "de:home",
"de:home", "", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page"), post_visid_high = c("", "3143668157394264962",
"3143668157394264962", "3143668157394264962", "3143668157394264962",
"3143668157394264962", "", "3143668157394264962", "3143668157394264962",
"3143668157394264962", "3143668157394264962", "", "3143668157394264962",
"3143668157394264962", "3143668157394264962", "3143668157394264962",
"3143668157394264962", "3143668157394264962", "3143668157394264962",
"3143668157394264962", "3143668157394264962", "3143668157394264962",
"3143668157394264962", "3143668157394264962", "3143668157394264962",
"3143694323709645433", "3143694323709645433", "3143694323709645433",
"3143808177623041281", "3143818698145480639", "3143861946318646987",
"3143888568673416567", "3143916363554296742", "3143994209836546636",
"3144182271422005983", "3144183559912197582", "3144200913727559565",
"3144208666143568153", "3144208666143568153", "3144282445091739050",
"3144326797071529895", "3144326797071529895", "3144348467329020534",
"3144361021518425949", "3144361021518425949", "3144361021518425949",
"3144372345199705820", "3144372345199705820", "3144372381706923662",
"3144373440416361528", "3144604891488470022"), post_visid_low = c("",
"6917530191577269031", "6917530191577269031", "6917530191577269031",
"6917530191577269031", "6917530191577269031", "", "6917530191577269031",
"6917530191577269031", "6917530191577269031", "6917530191577269031",
"", "6917530191577269031", "6917530191577269031", "6917530191577269031",
"6917530191577269031", "6917530191577269031", "6917530191577269031",
"6917530191577269031", "6917530191577269031", "6917530191577269031",
"6917530191577269031", "6917530191577269031", "6917530191577269031",
"6917530191577269031", "6012718983825451637", "6012718983825451637",
"6012718983825451637", "6917532342282135719", "6917530131447974250",
"4611689343268949020", "6917532348187708513", "6917530166344468751",
"6917530139501018314", "4611689319646876855", "4611689336826521421",
"6917532355703951791", "4611687154983112184", "4611687154983112184",
"6917532339597752130", "4611689342195339176", "4611689342195339176",
"4611689329847173482", "6917532347113971065", "6917532347113971065",
"6917532347113971065", "6917532332618432628", "6917532332618432628",
"4611689327162988203", "6917532342819023626", "2636988164942374912"
), va_closer_detail = c("8/4/2018 1:53:9 2 -120", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "8/4/2018 1:55:26 2 -120", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "de:mobile-content-page",
"8/4/2018 1:56:32 2 -120", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "n:Google - Germany:::empty::",
"de:contents", "de:mobile-content-page", "de:mobile-content-page",
"n:Google - Germany:::empty::", "de:contents", "p:Google - Germany:::empty::",
"n:Google - Germany:::empty::", "n:Google - Germany:::empty::",
"de:contents", "de:contents", "de:home", "de:home", "de:home",
"de:contents", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "n:Google - Germany:::empty::", "n:Google - Germany:::empty::",
"de:mobile-content-page", "de:contents", "de:mobile-content-page"
), va_closer_id = c("", "5", "5", "5", "5", "5", "", "5", "5",
"5", "5", "", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5",
"5", "5", "5", "5", "5", "5", "2", "5", "5", "5", "2", "5", "1",
"2", "2", "6", "6", "6", "6", "6", "5", "5", "5", "5", "2", "2",
"5", "5", "5"), va_finder_detail = c("", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "de:mobile-content-page", "de:mobile-content-page",
"de:contents", "de:contents", "de:mobile-content-page", "de:mobile-content-page",
"de:contents", "de:contents", "de:contents", "de:contents", "de:contents",
"de:contents", "de:contents", "de:home", "de:home", "de:home",
"de:contents", "de:mobile-content-page", "de:mobile-content-page",
"de:mobile-content-page", "de:home", "de:home", "de:mobile-content-page",
"de:contents", "de:mobile-content-page"), va_finder_id = c("",
"5", "5", "5", "5", "5", "", "5", "5", "5", "5", "", "5", "5",
"5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5",
"5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "6",
"6", "6", "5", "5", "5", "5", "6", "6", "5", "5", "5"), visit_num = c("",
"6", "6", "6", "6", "6", "", "6", "6", "6", "6", "", "6", "6",
"6", "6", "6", "6", "6", "6", "6", "6", "6", "6", "6", "3", "3",
"3", "1054", "487", "174", "56", "477", "1155", "1784", "977",
"256", "915", "915", "29", "151", "151", "1296", "843", "843",
"843", "906", "906", "23", "536", "62"), visit_page_num = c("",
"10", "11", "12", "13", "14", "", "16", "17", "18", "19", "",
"21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31",
"32", "33", "1", "2", "3", "1", "1", "1", "1", "1", "1", "1",
"1", "1", "1", "2", "1", "1", "2", "1", "1", "2", "3", "2", "3",
"1", "1", "1"), visit_start_time_gmt = c("3143668157394264962",
"1525736927", "1525736927", "1525736927", "1525736927", "1525736927",
"3143668157394264962", "1525736927", "1525736927", "1525736927",
"1525736927", "3143668157394264962", "1525736927", "1525736927",
"1525736927", "1525736927", "1525736927", "1525736927", "1525736927",
"1525736927", "1525736927", "1525736927", "1525736927", "1525736927",
"1525736927", "1525736201", "1525736201", "1525736201", "1525736763",
"1525737360", "1525736174", "1525736723", "1525736207", "1525736839",
"1525737132", "1525736460", "1525737437", "1525737070", "1525737070",
"1525736704", "1525737233", "1525737233", "1525737179", "1525736066",
"1525736066", "1525736066", "1525735643", "1525735643", "1525737342",
"1525735841", "1525736055"), timestamp = structure(c(3143668157394265088,
1525736927, 1525736927, 1525736927, 1525736927, 1525736927, 3143668157394265088,
1525736927, 1525736927, 1525736927, 1525736927, 3143668157394265088,
1525736927, 1525736927, 1525736927, 1525736927, 1525736927, 1525736927,
1525736927, 1525736927, 1525736927, 1525736927, 1525736927, 1525736927,
1525736927, 1525736201, 1525736201, 1525736201, 1525736763, 1525737360,
1525736174, 1525736723, 1525736207, 1525736839, 1525737132, 1525736460,
1525737437, 1525737070, 1525737070, 1525736704, 1525737233, 1525737233,
1525737179, 1525736066, 1525736066, 1525736066, 1525735643, 1525735643,
1525737342, 1525735841, 1525736055), class = c("POSIXct", "POSIXt"
), tzone = "UTC")), .Names = c("index_id", "campaign", "exclude_hit",
"first_hit_page_url", "first_hit_pagename", "first_hit_ref_domain",
"first_hit_ref_type", "first_hit_referrer", "first_hit_time_gmt",
"hit_source", "post_campaign", "post_cust_hit_time_gmt", "post_page_url",
"post_pagename", "post_visid_high", "post_visid_low", "va_closer_detail",
"va_closer_id", "va_finder_detail", "va_finder_id", "visit_num",
"visit_page_num", "visit_start_time_gmt", "timestamp"), row.names = c(94812L,
94814L, 94815L, 94816L, 94817L, 94818L, 94819L, 94821L, 94822L,
94823L, 94824L, 94825L, 94827L, 94828L, 94829L, 94830L, 94831L,
94832L, 94833L, 94834L, 94835L, 94836L, 94837L, 94838L, 94839L,
94840L, 94841L, 94842L, 94843L, 94844L, 94845L, 94846L, 94847L,
94848L, 94849L, 94850L, 94851L, 94852L, 94853L, 94854L, 94855L,
94856L, 94857L, 94858L, 94859L, 94860L, 94861L, 94862L, 94863L,
94864L, 94865L), class = "data.frame")
答案 0 :(得分:2)
dput(data_1$timestamp[1])
#structure(3143668157394265088, class = c("POSIXct", "POSIXt"), tzone = "UTC")
好,不是。
让我们学习help("POSIXct")
:
在所有已知的64位平台上以及我们在32位上使用的代码 Windows,可表示时间的范围是数十亿年:...
unclass(data_1$timestamp[1])/3600/24/365
#[1] 99685063337
#attr(,"tzone")
#[1] "UTC
那是数十亿年,而且很少。
好的,print.POSIXct
调用内部format.POSIXct
强制的POSIXlt
。现在,查看POSIXlt
对象的组成部分:
lapply(unclass(as.POSIXlt("2018-01-01")), class)
#$`sec`
#[1] "numeric"
#
#$min
#[1] "integer"
#
#$hour
#[1] "integer"
#
#$mday
#[1] "integer"
#
#$mon
#[1] "integer"
#
#$year
#[1] "integer"
#
#$wday
#[1] "integer"
#
#$yday
#[1] "integer"
#
#$isdst
#[1] "integer"
#
#$zone
#[1] "character"
#
#$gmtoff
#[1] "integer"
年份存储为整数。
.Machine$integer.max
#[1] 2147483647
这少于您拥有的年数,因此as.POSIXlt
将日期时间转换为NA
,并且为这些NA
对象打印了POSIXct
。
我认为您需要修复数据时间解析步骤。不要指望anytime
会出现奇迹。