Formatting two different dataframes with POSIXct for left_join()-ingThe difference between bracket [ ] and double bracket [[ ]] for accessing the elements of a list or dataframeHow R formats POSIXct with fractional secondsPOSIXct to numeric using different timezonesR: POSIXct time formattingCombining two time series with different ranges, when column headings are the datesTime zone missing from time seriesHow to merge a large dataset and a small dataset on POSIXct and Date respectively?Changing Time To A Comparable Function In RHow to convert a column of date/times to POSIXct when adding a decisecond character in R?Formatting Time in POSIXCT, Need Decimal Time

How do we know that black holes are spinning?

Can a business put whatever they want into a contract?

Are there objective criteria for classifying consonance v. dissonance?

Why is the UK still pressing on with Brexit?

How would you control supersoldiers in a late iron-age society?

What is a "major country" as named in Bernie Sanders' Healthcare debate answers?

What would happen if Protagoras v Euathlus were heard in court today?

Python web-scraper to download table of transistor counts from Wikipedia

Why does '/' contain '..'?

What does the Free Recovery sign (UK) actually mean?

Help with wheel lock

Why is the car dealer insisting on a loan instead of cash?

Expectation value of operators with non-zero Hamiltonian commutators

Output a Super Mario Image

In what sequence should an advanced civilization teach technology to medieval society to maximize rate of adoption?

Why any infinite sequence of real functions can be generated from a finite set through composition?

Why are some files not movable on Windows 10?

Impossible Scrabble Words

Good notation to require that z ≠ 0, -1, -2, -3, ...

What does this line from The hobbit mean?

Has Dumbledore ever scolded Harry?

How to publish superseding results without creating enemies

How to draw a Venn diagram for X - (Y intersect Z)?

Why is the year in this ISO timestamp not 2019?



Formatting two different dataframes with POSIXct for left_join()-ing


The difference between bracket [ ] and double bracket [[ ]] for accessing the elements of a list or dataframeHow R formats POSIXct with fractional secondsPOSIXct to numeric using different timezonesR: POSIXct time formattingCombining two time series with different ranges, when column headings are the datesTime zone missing from time seriesHow to merge a large dataset and a small dataset on POSIXct and Date respectively?Changing Time To A Comparable Function In RHow to convert a column of date/times to POSIXct when adding a decisecond character in R?Formatting Time in POSIXCT, Need Decimal Time






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm quite new to R and I'd like to left_join() the following two datasets:



> head(datagps)
Date & Time [Local] Latitude Longitude DateTime meters
1: 18/06/2018 03:16 -2.434613 34.85372 2018-06-18 03:16:00 12.036834
2: 18/06/2018 03:20 -2.434511 34.85376 2018-06-18 03:20:00 18.738134
3: 18/06/2018 03:24 -2.434503 34.85393 2018-06-18 03:24:00 26.781879
4: 18/06/2018 03:28 -2.434719 34.85382 2018-06-18 03:28:00 8.341659
5: 18/06/2018 03:33 -2.434718 34.85375 2018-06-18 03:33:00 11.332758
6: 18/06/2018 03:36 -2.434817 34.85377 2018-06-18 03:36:00 15.736907
> head(datasensorraw)
# A tibble: 6 x 4
TimeGroup x y z
<dttm> <int> <int> <dbl>
1 2018-06-09 04:48:00 3 5 5.83
2 2018-06-09 04:52:00 0 0 0
3 2018-06-09 04:56:00 29 31 42.8
4 2018-06-09 05:00:00 10 5 11.2
5 2018-06-09 05:04:00 2 10 10.2
6 2018-06-09 05:08:00 0 0 0


However, one of them is in POSIXct format and the other isn't, since I tried the code:



> dataresults<-left_join(datagps, datasensorraw, by = c("Date & Time [Local]" = "TimeGroup"))
Error in left_join_impl(x, y, by_x, by_y, aux_x, aux_y, na_matches) :
cannot join a POSIXct object with an object that is not a POSIXct object


How to know which one of the two is in POSIXct format and how to format the other one so I can left_join() successfully? I've looked at other examples but I can't understand when - or / needs to be used.



Any input is appreciated!










share|improve this question
























  • As the error says, convert theDate & Time [Local] into POSIXct

    – akrun
    Mar 28 at 12:30

















1















I'm quite new to R and I'd like to left_join() the following two datasets:



> head(datagps)
Date & Time [Local] Latitude Longitude DateTime meters
1: 18/06/2018 03:16 -2.434613 34.85372 2018-06-18 03:16:00 12.036834
2: 18/06/2018 03:20 -2.434511 34.85376 2018-06-18 03:20:00 18.738134
3: 18/06/2018 03:24 -2.434503 34.85393 2018-06-18 03:24:00 26.781879
4: 18/06/2018 03:28 -2.434719 34.85382 2018-06-18 03:28:00 8.341659
5: 18/06/2018 03:33 -2.434718 34.85375 2018-06-18 03:33:00 11.332758
6: 18/06/2018 03:36 -2.434817 34.85377 2018-06-18 03:36:00 15.736907
> head(datasensorraw)
# A tibble: 6 x 4
TimeGroup x y z
<dttm> <int> <int> <dbl>
1 2018-06-09 04:48:00 3 5 5.83
2 2018-06-09 04:52:00 0 0 0
3 2018-06-09 04:56:00 29 31 42.8
4 2018-06-09 05:00:00 10 5 11.2
5 2018-06-09 05:04:00 2 10 10.2
6 2018-06-09 05:08:00 0 0 0


However, one of them is in POSIXct format and the other isn't, since I tried the code:



> dataresults<-left_join(datagps, datasensorraw, by = c("Date & Time [Local]" = "TimeGroup"))
Error in left_join_impl(x, y, by_x, by_y, aux_x, aux_y, na_matches) :
cannot join a POSIXct object with an object that is not a POSIXct object


How to know which one of the two is in POSIXct format and how to format the other one so I can left_join() successfully? I've looked at other examples but I can't understand when - or / needs to be used.



Any input is appreciated!










share|improve this question
























  • As the error says, convert theDate & Time [Local] into POSIXct

    – akrun
    Mar 28 at 12:30













1












1








1








I'm quite new to R and I'd like to left_join() the following two datasets:



> head(datagps)
Date & Time [Local] Latitude Longitude DateTime meters
1: 18/06/2018 03:16 -2.434613 34.85372 2018-06-18 03:16:00 12.036834
2: 18/06/2018 03:20 -2.434511 34.85376 2018-06-18 03:20:00 18.738134
3: 18/06/2018 03:24 -2.434503 34.85393 2018-06-18 03:24:00 26.781879
4: 18/06/2018 03:28 -2.434719 34.85382 2018-06-18 03:28:00 8.341659
5: 18/06/2018 03:33 -2.434718 34.85375 2018-06-18 03:33:00 11.332758
6: 18/06/2018 03:36 -2.434817 34.85377 2018-06-18 03:36:00 15.736907
> head(datasensorraw)
# A tibble: 6 x 4
TimeGroup x y z
<dttm> <int> <int> <dbl>
1 2018-06-09 04:48:00 3 5 5.83
2 2018-06-09 04:52:00 0 0 0
3 2018-06-09 04:56:00 29 31 42.8
4 2018-06-09 05:00:00 10 5 11.2
5 2018-06-09 05:04:00 2 10 10.2
6 2018-06-09 05:08:00 0 0 0


However, one of them is in POSIXct format and the other isn't, since I tried the code:



> dataresults<-left_join(datagps, datasensorraw, by = c("Date & Time [Local]" = "TimeGroup"))
Error in left_join_impl(x, y, by_x, by_y, aux_x, aux_y, na_matches) :
cannot join a POSIXct object with an object that is not a POSIXct object


How to know which one of the two is in POSIXct format and how to format the other one so I can left_join() successfully? I've looked at other examples but I can't understand when - or / needs to be used.



Any input is appreciated!










share|improve this question














I'm quite new to R and I'd like to left_join() the following two datasets:



> head(datagps)
Date & Time [Local] Latitude Longitude DateTime meters
1: 18/06/2018 03:16 -2.434613 34.85372 2018-06-18 03:16:00 12.036834
2: 18/06/2018 03:20 -2.434511 34.85376 2018-06-18 03:20:00 18.738134
3: 18/06/2018 03:24 -2.434503 34.85393 2018-06-18 03:24:00 26.781879
4: 18/06/2018 03:28 -2.434719 34.85382 2018-06-18 03:28:00 8.341659
5: 18/06/2018 03:33 -2.434718 34.85375 2018-06-18 03:33:00 11.332758
6: 18/06/2018 03:36 -2.434817 34.85377 2018-06-18 03:36:00 15.736907
> head(datasensorraw)
# A tibble: 6 x 4
TimeGroup x y z
<dttm> <int> <int> <dbl>
1 2018-06-09 04:48:00 3 5 5.83
2 2018-06-09 04:52:00 0 0 0
3 2018-06-09 04:56:00 29 31 42.8
4 2018-06-09 05:00:00 10 5 11.2
5 2018-06-09 05:04:00 2 10 10.2
6 2018-06-09 05:08:00 0 0 0


However, one of them is in POSIXct format and the other isn't, since I tried the code:



> dataresults<-left_join(datagps, datasensorraw, by = c("Date & Time [Local]" = "TimeGroup"))
Error in left_join_impl(x, y, by_x, by_y, aux_x, aux_y, na_matches) :
cannot join a POSIXct object with an object that is not a POSIXct object


How to know which one of the two is in POSIXct format and how to format the other one so I can left_join() successfully? I've looked at other examples but I can't understand when - or / needs to be used.



Any input is appreciated!







r posixct






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 12:29









juancda4juancda4

1186 bronze badges




1186 bronze badges















  • As the error says, convert theDate & Time [Local] into POSIXct

    – akrun
    Mar 28 at 12:30

















  • As the error says, convert theDate & Time [Local] into POSIXct

    – akrun
    Mar 28 at 12:30
















As the error says, convert theDate & Time [Local] into POSIXct

– akrun
Mar 28 at 12:30





As the error says, convert theDate & Time [Local] into POSIXct

– akrun
Mar 28 at 12:30












1 Answer
1






active

oldest

votes


















1
















It is because the first dataset column Date & Time [Local] is not 'DateTime' class. Converting to POSIXct would solve the issue



library(dplyr)
datagps %>%
mutate(`Date & Time [Local]` = as.POSIXct(`Date & Time [Local]`,
format = "%d/%m/%Y %H:%M")) %>%
left_join(datasensorraw, by = c("Date & Time [Local]" = "TimeGroup"))





share|improve this answer



























  • Thank you for your answer. I got:> library(dplyr) > datagps %>% + format = "%d/%m/%Y %H:%M")) %>% Error: unexpected ')' in: "datagps %>% format = "%d/%m/%Y %H:%M")"

    – juancda4
    Mar 28 at 12:39











  • @juancda4 Sorry a typo, it should have an enclosing bracket at the end. updated

    – akrun
    Mar 28 at 12:40










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55397675%2fformatting-two-different-dataframes-with-posixct-for-left-join-ing%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1
















It is because the first dataset column Date & Time [Local] is not 'DateTime' class. Converting to POSIXct would solve the issue



library(dplyr)
datagps %>%
mutate(`Date & Time [Local]` = as.POSIXct(`Date & Time [Local]`,
format = "%d/%m/%Y %H:%M")) %>%
left_join(datasensorraw, by = c("Date & Time [Local]" = "TimeGroup"))





share|improve this answer



























  • Thank you for your answer. I got:> library(dplyr) > datagps %>% + format = "%d/%m/%Y %H:%M")) %>% Error: unexpected ')' in: "datagps %>% format = "%d/%m/%Y %H:%M")"

    – juancda4
    Mar 28 at 12:39











  • @juancda4 Sorry a typo, it should have an enclosing bracket at the end. updated

    – akrun
    Mar 28 at 12:40















1
















It is because the first dataset column Date & Time [Local] is not 'DateTime' class. Converting to POSIXct would solve the issue



library(dplyr)
datagps %>%
mutate(`Date & Time [Local]` = as.POSIXct(`Date & Time [Local]`,
format = "%d/%m/%Y %H:%M")) %>%
left_join(datasensorraw, by = c("Date & Time [Local]" = "TimeGroup"))





share|improve this answer



























  • Thank you for your answer. I got:> library(dplyr) > datagps %>% + format = "%d/%m/%Y %H:%M")) %>% Error: unexpected ')' in: "datagps %>% format = "%d/%m/%Y %H:%M")"

    – juancda4
    Mar 28 at 12:39











  • @juancda4 Sorry a typo, it should have an enclosing bracket at the end. updated

    – akrun
    Mar 28 at 12:40













1














1










1









It is because the first dataset column Date & Time [Local] is not 'DateTime' class. Converting to POSIXct would solve the issue



library(dplyr)
datagps %>%
mutate(`Date & Time [Local]` = as.POSIXct(`Date & Time [Local]`,
format = "%d/%m/%Y %H:%M")) %>%
left_join(datasensorraw, by = c("Date & Time [Local]" = "TimeGroup"))





share|improve this answer















It is because the first dataset column Date & Time [Local] is not 'DateTime' class. Converting to POSIXct would solve the issue



library(dplyr)
datagps %>%
mutate(`Date & Time [Local]` = as.POSIXct(`Date & Time [Local]`,
format = "%d/%m/%Y %H:%M")) %>%
left_join(datasensorraw, by = c("Date & Time [Local]" = "TimeGroup"))






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 28 at 12:39

























answered Mar 28 at 12:32









akrunakrun

467k15 gold badges261 silver badges343 bronze badges




467k15 gold badges261 silver badges343 bronze badges















  • Thank you for your answer. I got:> library(dplyr) > datagps %>% + format = "%d/%m/%Y %H:%M")) %>% Error: unexpected ')' in: "datagps %>% format = "%d/%m/%Y %H:%M")"

    – juancda4
    Mar 28 at 12:39











  • @juancda4 Sorry a typo, it should have an enclosing bracket at the end. updated

    – akrun
    Mar 28 at 12:40

















  • Thank you for your answer. I got:> library(dplyr) > datagps %>% + format = "%d/%m/%Y %H:%M")) %>% Error: unexpected ')' in: "datagps %>% format = "%d/%m/%Y %H:%M")"

    – juancda4
    Mar 28 at 12:39











  • @juancda4 Sorry a typo, it should have an enclosing bracket at the end. updated

    – akrun
    Mar 28 at 12:40
















Thank you for your answer. I got:> library(dplyr) > datagps %>% + format = "%d/%m/%Y %H:%M")) %>% Error: unexpected ')' in: "datagps %>% format = "%d/%m/%Y %H:%M")"

– juancda4
Mar 28 at 12:39





Thank you for your answer. I got:> library(dplyr) > datagps %>% + format = "%d/%m/%Y %H:%M")) %>% Error: unexpected ')' in: "datagps %>% format = "%d/%m/%Y %H:%M")"

– juancda4
Mar 28 at 12:39













@juancda4 Sorry a typo, it should have an enclosing bracket at the end. updated

– akrun
Mar 28 at 12:40





@juancda4 Sorry a typo, it should have an enclosing bracket at the end. updated

– akrun
Mar 28 at 12:40








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55397675%2fformatting-two-different-dataframes-with-posixct-for-left-join-ing%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript