Warning & Error when “filling missing data” in R










0















I asked two questions before about filling missing data:



(Ⅰ)Question_one
(Ⅱ)Question_two



It almost succeed when I follow the advice but still have one warning and one error.



I use codes below to import data from Excel. (You can download this file in this Google Drive website):



#read form clipborad, which is copied in "Example_a.xlsx"
# read dt_A
dt_A <- read.delim("clipboard",header=TRUE)
# read dt_B
dt_B <- read.delim("clipboard",header=TRUE)


Then, I change the charcter into "Date" format:



#Change "Date" to date format
as.POSIXct(dt_A$Date, format="%m/%d/%Y %H:%M")
as.POSIXct(dt_B$Date, format="%m/%d/%Y %H:%M")


However, when I use "complete" (adviced by AntoniosK) to fill the missing date, a warning occurs.



library(tidyverse)
# complete dates of data B using dates of data A
df <- dt_B %>% complete(Date = dt_A[1])


The warning is:



Warning message:
Column `Date` joining factors with different levels, coercing to character vector


However, df seems to meet the expectation (Fig.1). Then, I ignore this warning and use codes adviced by Jay Achar:



library(dplyr)
library(lubridate)

df %>%
mutate(B_Value = ifelse(is.na(B_Value),
lag(B_Value, 1) + (lead(B_Value, 1) - lag(B_Value, 1)) *
as.numeric(difftime(Date, lag(Date, 1))) /
as.numeric((difftime(lead(Date, 1), Date) + difftime(Date, lag(Date, 1)))),
B_Value)) %>%
mutate(B_Value = round(B_Value, 2))


There occurs an error:



Error in mutate_impl(.data, dots) : 
Evaluation error: character string is not in a standard unambiguous format.


Could you teach me why there is a warning & an error?



Fig-1










share|improve this question



















  • 1





    as.POSIXct(dt_B$Date, format="%m/%d/%Y %H:%M") this should be dt_B$Date <- as.POSIXct(dt_B$Date, format="%m/%d/%Y %H:%M")

    – zx8754
    Nov 15 '18 at 7:24















0















I asked two questions before about filling missing data:



(Ⅰ)Question_one
(Ⅱ)Question_two



It almost succeed when I follow the advice but still have one warning and one error.



I use codes below to import data from Excel. (You can download this file in this Google Drive website):



#read form clipborad, which is copied in "Example_a.xlsx"
# read dt_A
dt_A <- read.delim("clipboard",header=TRUE)
# read dt_B
dt_B <- read.delim("clipboard",header=TRUE)


Then, I change the charcter into "Date" format:



#Change "Date" to date format
as.POSIXct(dt_A$Date, format="%m/%d/%Y %H:%M")
as.POSIXct(dt_B$Date, format="%m/%d/%Y %H:%M")


However, when I use "complete" (adviced by AntoniosK) to fill the missing date, a warning occurs.



library(tidyverse)
# complete dates of data B using dates of data A
df <- dt_B %>% complete(Date = dt_A[1])


The warning is:



Warning message:
Column `Date` joining factors with different levels, coercing to character vector


However, df seems to meet the expectation (Fig.1). Then, I ignore this warning and use codes adviced by Jay Achar:



library(dplyr)
library(lubridate)

df %>%
mutate(B_Value = ifelse(is.na(B_Value),
lag(B_Value, 1) + (lead(B_Value, 1) - lag(B_Value, 1)) *
as.numeric(difftime(Date, lag(Date, 1))) /
as.numeric((difftime(lead(Date, 1), Date) + difftime(Date, lag(Date, 1)))),
B_Value)) %>%
mutate(B_Value = round(B_Value, 2))


There occurs an error:



Error in mutate_impl(.data, dots) : 
Evaluation error: character string is not in a standard unambiguous format.


Could you teach me why there is a warning & an error?



Fig-1










share|improve this question



















  • 1





    as.POSIXct(dt_B$Date, format="%m/%d/%Y %H:%M") this should be dt_B$Date <- as.POSIXct(dt_B$Date, format="%m/%d/%Y %H:%M")

    – zx8754
    Nov 15 '18 at 7:24













0












0








0








I asked two questions before about filling missing data:



(Ⅰ)Question_one
(Ⅱ)Question_two



It almost succeed when I follow the advice but still have one warning and one error.



I use codes below to import data from Excel. (You can download this file in this Google Drive website):



#read form clipborad, which is copied in "Example_a.xlsx"
# read dt_A
dt_A <- read.delim("clipboard",header=TRUE)
# read dt_B
dt_B <- read.delim("clipboard",header=TRUE)


Then, I change the charcter into "Date" format:



#Change "Date" to date format
as.POSIXct(dt_A$Date, format="%m/%d/%Y %H:%M")
as.POSIXct(dt_B$Date, format="%m/%d/%Y %H:%M")


However, when I use "complete" (adviced by AntoniosK) to fill the missing date, a warning occurs.



library(tidyverse)
# complete dates of data B using dates of data A
df <- dt_B %>% complete(Date = dt_A[1])


The warning is:



Warning message:
Column `Date` joining factors with different levels, coercing to character vector


However, df seems to meet the expectation (Fig.1). Then, I ignore this warning and use codes adviced by Jay Achar:



library(dplyr)
library(lubridate)

df %>%
mutate(B_Value = ifelse(is.na(B_Value),
lag(B_Value, 1) + (lead(B_Value, 1) - lag(B_Value, 1)) *
as.numeric(difftime(Date, lag(Date, 1))) /
as.numeric((difftime(lead(Date, 1), Date) + difftime(Date, lag(Date, 1)))),
B_Value)) %>%
mutate(B_Value = round(B_Value, 2))


There occurs an error:



Error in mutate_impl(.data, dots) : 
Evaluation error: character string is not in a standard unambiguous format.


Could you teach me why there is a warning & an error?



Fig-1










share|improve this question
















I asked two questions before about filling missing data:



(Ⅰ)Question_one
(Ⅱ)Question_two



It almost succeed when I follow the advice but still have one warning and one error.



I use codes below to import data from Excel. (You can download this file in this Google Drive website):



#read form clipborad, which is copied in "Example_a.xlsx"
# read dt_A
dt_A <- read.delim("clipboard",header=TRUE)
# read dt_B
dt_B <- read.delim("clipboard",header=TRUE)


Then, I change the charcter into "Date" format:



#Change "Date" to date format
as.POSIXct(dt_A$Date, format="%m/%d/%Y %H:%M")
as.POSIXct(dt_B$Date, format="%m/%d/%Y %H:%M")


However, when I use "complete" (adviced by AntoniosK) to fill the missing date, a warning occurs.



library(tidyverse)
# complete dates of data B using dates of data A
df <- dt_B %>% complete(Date = dt_A[1])


The warning is:



Warning message:
Column `Date` joining factors with different levels, coercing to character vector


However, df seems to meet the expectation (Fig.1). Then, I ignore this warning and use codes adviced by Jay Achar:



library(dplyr)
library(lubridate)

df %>%
mutate(B_Value = ifelse(is.na(B_Value),
lag(B_Value, 1) + (lead(B_Value, 1) - lag(B_Value, 1)) *
as.numeric(difftime(Date, lag(Date, 1))) /
as.numeric((difftime(lead(Date, 1), Date) + difftime(Date, lag(Date, 1)))),
B_Value)) %>%
mutate(B_Value = round(B_Value, 2))


There occurs an error:



Error in mutate_impl(.data, dots) : 
Evaluation error: character string is not in a standard unambiguous format.


Could you teach me why there is a warning & an error?



Fig-1







r datetime






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 7:26









zx8754

30.2k763101




30.2k763101










asked Nov 15 '18 at 7:06









T XT X

128116




128116







  • 1





    as.POSIXct(dt_B$Date, format="%m/%d/%Y %H:%M") this should be dt_B$Date <- as.POSIXct(dt_B$Date, format="%m/%d/%Y %H:%M")

    – zx8754
    Nov 15 '18 at 7:24












  • 1





    as.POSIXct(dt_B$Date, format="%m/%d/%Y %H:%M") this should be dt_B$Date <- as.POSIXct(dt_B$Date, format="%m/%d/%Y %H:%M")

    – zx8754
    Nov 15 '18 at 7:24







1




1





as.POSIXct(dt_B$Date, format="%m/%d/%Y %H:%M") this should be dt_B$Date <- as.POSIXct(dt_B$Date, format="%m/%d/%Y %H:%M")

– zx8754
Nov 15 '18 at 7:24





as.POSIXct(dt_B$Date, format="%m/%d/%Y %H:%M") this should be dt_B$Date <- as.POSIXct(dt_B$Date, format="%m/%d/%Y %H:%M")

– zx8754
Nov 15 '18 at 7:24












0






active

oldest

votes











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/3.0/"u003ecc by-sa 3.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%2f53314087%2fwarning-error-when-filling-missing-data-in-r%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















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%2f53314087%2fwarning-error-when-filling-missing-data-in-r%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







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto