tibble

Get data frame into right format from web-scrapping work [closed]

帅比萌擦擦* 提交于 2019-12-02 14:23:45
I have code which I use to web scrape past air atmosphere data repeatedly by wrapping the httr in the function.The original code works well on looping task. You may find the original code here https://stackoverflow.com/a/52545775/7356308 . I modified it a bit to web-scrap different part in the website. Unfortunately it didn't return right format especially the observation time. #' @param region one of "`naconf`", "`samer`", "`pac`", "`nz`", "`ant`", "`np`", #' "`europe`", "`africa`", "`seasia`", "`mideast`" (which matches the #' values of the drop-down menu on the site) #' @param date an ISO

Column name of last non-NA row per row; using tidyverse solution?

假装没事ソ 提交于 2019-12-02 02:42:13
Brief Dataset description: I have survey data generated from Qualtrics, which I've imported into R as a tibble. Each column corresponds to a survey question, and I've preserved the original column order (to correspond with the order of the questions in the survey). Problem in plain language: Due to normal participant attrition, not all participants completed all of the questions in the survey. I want to know how far each participant got in the survey, and the last question they each answered before stopping. Problem statement in R: I want to generate (using tidyverse): 1) A new column ( lastq

mutate_if, summarize_at etc coerce data.table to data.frame

こ雲淡風輕ζ 提交于 2019-12-02 01:49:14
问题 It seems like some dplyr functions, including mutate_if , mutate_all , mutate_at etc coerce data.table inputs to data.frame. That seems like strange behaviour, even though it is documented in ?mutate_all (Under 'Value', it says 'data.frame' - but it does not coerce tibbles to data.frames.) require(dplyr) require(data.table) data("iris") dt <- as.data.table(iris) class(dt) #[1] "data.table" "data.frame" class(mutate_if(dt, is.numeric, as.numeric)) #[1] "data.frame" However, this does not

R: Join two tables (tibbles) by *list* columns

拥有回忆 提交于 2019-12-02 00:19:47
问题 Seems like there should be a simple answer for this but I haven't been able to find one: tib1 <- tibble(x = list(1, 2, 3), y = list(4, 5, 6)) tib1 # A tibble: 3 × 2 x y <list> <list> 1 <dbl [1]> <dbl [1]> 2 <dbl [1]> <dbl [1]> 3 <dbl [1]> <dbl [1]> tib2 <- tibble(x = list(1, 2, 4, 5), y = list(4, c(5, 10), 6, 7)) tib2 # A tibble: 4 × 2 x y <list> <list> 1 <dbl [1]> <dbl [1]> 2 <dbl [1]> <dbl [2]> 3 <dbl [1]> <dbl [1]> 4 <dbl [1]> <dbl [1]> dplyr::inner_join(tib1, tib2) Joining, by = c("x", "y

How to make tibbles display significant digits

北城余情 提交于 2019-12-01 11:11:28
I am working with data that has significant digits (i.e. digits after the "."). These digits appear when viewing my data both as a variable in base R, and also when the data is stored in a dataframe. However, they do not appear when I view the data in a tibble. I need to view these significant digits for my work. Is there a way to make them appear when using tibbles? Here is a reproducible example: x has 5 significant digits, and 3 are displayed when using base R: x = 1234.56789 x [1] 1234.568 Within a data.frame, 3 significant digits are also displayed: df = data.frame(x=x) df x 1 1234.568

How to make tibbles display significant digits

萝らか妹 提交于 2019-12-01 07:51:39
问题 I am working with data that has significant digits (i.e. digits after the "."). These digits appear when viewing my data both as a variable in base R, and also when the data is stored in a dataframe. However, they do not appear when I view the data in a tibble. I need to view these significant digits for my work. Is there a way to make them appear when using tibbles? Here is a reproducible example: x has 5 significant digits, and 3 are displayed when using base R: x = 1234.56789 x [1] 1234

Error in bind_rows_(x, .id) : Column can't be converted from factor to numeric

馋奶兔 提交于 2019-11-29 07:33:34
I have ten datasets that have been read from Excel files, using the xlsx library, and stored in tibbles. I want to merge them. Here are example datasets. The number of variables differ between datasets, and some variables are only in one dataset. The value of the person variable will never overlap. data1 <- tibble(person = c("A","B","C"), test1 = as.factor(c(1,4,5)), test2 = c(14,25,10), test3 = c(12.5,16.0,4), test4 = c(16,23,21), test5 = as.factor(c(49,36,52))) data2 <- tibble(person = c("D","E","F"), test1 = c(8,7,2), test3 = c(6.5,12.0,19.5), test4 = as.factor(c(15,21,29)), test5 = as

Why does as_tibble() round floats to the nearest integer?

让人想犯罪 __ 提交于 2019-11-28 03:27:16
问题 When using as_tibble in dplyr 0.7.4 and R 3.4.1 I get the following outputs mtcars %>% aggregate(disp ~ cyl, data=., mean) %>% as_tibble() which outputs # A tibble: 3 x 2 cyl disp <dbl> <dbl> 1 4.00 105 2 6.00 183 3 8.00 353 while mtcars %>% aggregate(disp ~ cyl, data=., mean) outputs cyl disp 1 4 105.1364 2 6 183.3143 3 8 353.1000 Not really surprisingly, the following mtcars %>% group_by(cyl) %>% summarise(disp=mean(disp)) gives again # A tibble: 3 x 2 cyl disp <dbl> <dbl> 1 4.00 105 2 6.00

Error in bind_rows_(x, .id) : Column can't be converted from factor to numeric

血红的双手。 提交于 2019-11-28 00:50:52
问题 I have ten datasets that have been read from Excel files, using the xlsx library, and stored in tibbles. I want to merge them. Here are example datasets. The number of variables differ between datasets, and some variables are only in one dataset. The value of the person variable will never overlap. data1 <- tibble(person = c("A","B","C"), test1 = as.factor(c(1,4,5)), test2 = c(14,25,10), test3 = c(12.5,16.0,4), test4 = c(16,23,21), test5 = as.factor(c(49,36,52))) data2 <- tibble(person = c("D

Inputting NA where there are missing values when scraping with rvest

不打扰是莪最后的温柔 提交于 2019-11-27 08:33:09
问题 I want to use rvest to scrape a page which has titles and run times of talks at a recent conference and then combine the values into a tibble library(tibble) library(rvest) url <- "https://channel9.msdn.com/Events/useR-international-R-User-conferences/useR-International-R-User-2017-Conference?sort=status&direction=desc&page=14" title <- page %>% html_nodes("h3 a") %>% html_text() length <- page %>% html_nodes(".tile .caption") %>% html_text() df <- tibble(title,length) If you look at the page