r

Joining dataframes from lists of unequal length

白昼怎懂夜的黑 提交于 2021-02-10 06:15:19
问题 I have two lists of dataframes that I want to combine, I have tried the following: A <- data.frame(ID = c(1,2,3), var1 = c(3,4,5), var2 = c(6,3,2)) B <- data.frame(ID = c(1,2,3), var1 = c(4,4,5), var2 = c(6,7,3)) C <- data.frame(ID = c(1,2,3), var1 = c(1,4,8), var2 = c(9,2,3)) list1 <- list(A = A, B = B, C = C) list2 <- list(A = A, B = B) combined <- map2(list1, list2, full_join, by = 'ID') This returns an error that the two lists are of different lengths. The only other way I have thought of

Joining dataframes from lists of unequal length

僤鯓⒐⒋嵵緔 提交于 2021-02-10 06:15:17
问题 I have two lists of dataframes that I want to combine, I have tried the following: A <- data.frame(ID = c(1,2,3), var1 = c(3,4,5), var2 = c(6,3,2)) B <- data.frame(ID = c(1,2,3), var1 = c(4,4,5), var2 = c(6,7,3)) C <- data.frame(ID = c(1,2,3), var1 = c(1,4,8), var2 = c(9,2,3)) list1 <- list(A = A, B = B, C = C) list2 <- list(A = A, B = B) combined <- map2(list1, list2, full_join, by = 'ID') This returns an error that the two lists are of different lengths. The only other way I have thought of

Return values with matching conditions in r

时光毁灭记忆、已成空白 提交于 2021-02-10 06:14:43
问题 I would like to return values with matching conditions in another column based on a cut score criterion. If the cut scores are not available in the variable, I would like to grab closest larger value. Here is a snapshot of dataset: ids <- c(1,2,3,4,5,6,7,8,9,10) scores.a <- c(512,531,541,555,562,565,570,572,573,588) scores.b <- c(12,13,14,15,16,17,18,19,20,21) data <- data.frame(ids, scores.a, scores.b) > data ids scores.a scores.b 1 1 512 12 2 2 531 13 3 3 541 14 4 4 555 15 5 5 562 16 6 6

How to rotate igraph network plot?

纵然是瞬间 提交于 2021-02-10 06:14:37
问题 I'm trying to rotate the R package based igraph network plot. In the igraph guidebook not enough explanation how to use R code tk_rotate(tkp.id, degree = NULL, rad = NULL) 回答1: For the R package igraph according to the documentation: the tk_rotate rotates the figure, its parameter can be given either in degrees or in radians. Of particular note is the argument tkp.id . Make sure you assign the tkplot window to this value so you can reference it as the tkp.id in the function. tkp.id The id of

Adding name of file when using sparklyr::spark_read_json

谁说我不能喝 提交于 2021-02-10 06:14:30
问题 I have millions of json-files, where each of the files contains the same number of columns, lets say x and y . Note that the length of x and y is equal for a single file, but could be different when comparing two different files. The problem is that the only thing that separates the data is the name of the file. So when combining the files I'd like to have the name of the file included as a third column. Is this possible using sparklyr::spark_read_json , i.e. when using wildcards? MWE:

How to download all sheets in a google sheet in R

我的未来我决定 提交于 2021-02-10 06:14:18
问题 I'm looking to download all of the sheets in a single google sheet in R. I'm currently using the gsheet package by [maxconway][1] , which allows me to download a sheet using its URL, but it only works on individual sheets, which are differentiated by a gid . The set of google sheets I'm trying to download has over 100 sheets, which makes downloading them one by one with gsheet massively inconvenient - does anyone know of any R packages that automate this or of any way to loop through all of

How to download all sheets in a google sheet in R

倖福魔咒の 提交于 2021-02-10 06:13:20
问题 I'm looking to download all of the sheets in a single google sheet in R. I'm currently using the gsheet package by [maxconway][1] , which allows me to download a sheet using its URL, but it only works on individual sheets, which are differentiated by a gid . The set of google sheets I'm trying to download has over 100 sheets, which makes downloading them one by one with gsheet massively inconvenient - does anyone know of any R packages that automate this or of any way to loop through all of

How to make variable width histogram in R with labels aligned to bin edges?

眉间皱痕 提交于 2021-02-10 06:13:20
问题 I'm using ggplot2 , which by default creates histograms with fixed bin widths and whose bin labels are plotted in the center of each bin. What I want instead is a variable-width histogram whose bin labels are representative of the end points of each bin, like this plot: To produce this example plot, I manually entered the bin parameters and shifted the bins to align them with their end points: income=data.frame(lx=c(0,10,25,50,100),rx=c(10,25,50,100,150),y=c(20,28,27,18,7)) income$width =

rvest function html_nodes returns {xml_nodeset (0)}

余生长醉 提交于 2021-02-10 06:13:05
问题 I am trying to scrape data frame the following website http://stats.nba.com/game/0041700404/playbyplay/ I'd like to create a table that includes the date of the game, the scores throughout the game, and the team names I am using the following code: game1 <- read_html("http://stats.nba.com/game/0041700404/playbyplay/") #Extracts the Date html_nodes(game1, xpath = '//*[contains(concat( " ", @class, " " ), concat( " ", "game-summary-team--vtm", " " ))]//*[contains(concat( " ", @class, " " ),

Errorbars on grouped barplots in ggplot2

会有一股神秘感。 提交于 2021-02-10 06:12:56
问题 I need to plot a grouped barplot with different error bars for each bar in each group. I have managed to plot the chart and add the error bars but they are not positioned correctly on the graph (see below) I know I know I need to somehow tell the errorbars which Genotype they need to be attached to, but I'm not quite sure how. I have tried to use this: Grouped barplot in R with error bars but can't work out what's different. Code: ggplot(data=leaf_level) + geom_bar(aes(x=factor(DAS), y=Total