Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in Data Frame #3

Open
mohanwugupta opened this issue Aug 9, 2018 · 4 comments
Open

Error in Data Frame #3

mohanwugupta opened this issue Aug 9, 2018 · 4 comments

Comments

@mohanwugupta
Copy link

Hi,

I'm trying to run the powerstate_preprocessing function. I ran it and error occurred which I traced to the hours function. The exact error I'm getting is: "Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 11, 1963". It is occurring because on line 10 inside the map function is transforming the hours variable into 11 observations versus the needed 1963 observations. This is a problem on line 14 when cbind is applied and that's when the error occurs.

Thoughts?

@mariasimoneau
Copy link

Thanks for your post and for pointing this out. We continue to work on the code base and this may get fixed as part of an effort to re-write code but there's not a particular schedule for that. In the mean time, we welcome your contributions. Thanks again.

@mohanwugupta
Copy link
Author

Ah okay, I understand. I'll try and come with a solution in the coming weeks.

@mtpan
Copy link

mtpan commented Oct 5, 2018

Hi,

I've come up with a solution for the hours.R function only in the context of powerstate_preprocessing function. I have not tested how it works in other functions yet. Basically, I replaced the mapper function with a for loop to get it to work. I'm not sure why this solution works but it seems to work across multiple datasets.
hours.txt

@brainfood
Copy link

So this comes long after the last comment, but here's a modified version of the hours() function that works for me across several of the pre-processing functions.

hours = function(timestamps){ 
    days = timestamps %>% unlist %>% as.POSIXlt(origin = "1970-01-01") %>%
        as.character %>%
        map(function(x){if(is.na(x)){return(c("NA","NA"))}else{return(strsplit(x, " "))}}) %>%
        unlist %>%
        matrix(nrow=2) %>%
        t
    hours =
        days[,2] %>% 
        map(strsplit, split=":") %>% 
        unlist() %>% 
        as.numeric() %>% #Convert from factor
        matrix(ncol=3, byrow = TRUE) %>% 
        data.frame() %>% 
        dplyr::rename(hour=X1, min=X2, sec=X3) %>%
        apply(1, function(times) sum(times * c(1, 1/60, 1/3600)))
    days = days[,1]
    output = as_data_frame(cbind(hours=hours, days=days))
    output["hours"] = lapply(output["hours"], as.numeric)
    return(output)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants