r

R - merge 2 dataframes with timestamp between

 ̄綄美尐妖づ 提交于 2021-02-10 14:41:03
问题 DF1: structure(list(X = c(113.8577674, 113.8577537, 113.8577403), Y = c(22.19537297, 22.19537222, 22.1953723), Date = c("7/1/2016", "7/1/2016", "7/1/2016"), Time = structure(c(9474, 9484, 9494 ), class = c("hms", "difftime"), units = "secs"), TrackTime = structure(c(38274, 38284, 38294), class = c("hms", "difftime"), units = "secs")), .Names = c("X", "Y", "Date", "Time", "TrackTime"), row.names = c(NA, -3L), class = "data.frame", spec = structure(list( cols = structure(list(X = structure(list

How to use dplyr `rowwise()` column numbers instead of column names

北慕城南 提交于 2021-02-10 14:39:41
问题 library(tidyverse) df <- tibble(col1 = c(5, 2), col2 = c(6, 4), col3 = c(9, 9)) df %>% rowwise() %>% mutate(col4 = sd(c(col1, col3))) # # A tibble: 2 x 4 # col1 col2 col3 col4 # <dbl> <dbl> <dbl> <dbl> # 1 5 6 9 2.83 # 2 2 4 9 4.95 After asking a series of questions I can finally calculate standard deviation across rows. See my code above. But I can't use column names in my production code, because the database I pull from likes to change the column names periodically. Lucky for me the

Finding the differences of paired-columns using dplyr

一曲冷凌霜 提交于 2021-02-10 14:38:09
问题 set.seed(3) library(dplyr) dat <- tibble(Measure = c("Height","Weight","Width","Length"), AD1_1= rpois(4,10), AD1_2= rpois(4,9), AD2_1= rpois(4,10), AD2_2= rpois(4,9), AD3_1= rpois(4,10), AD3_2= rpois(4,9), AD4_1= rpois(4,10), AD4_2= rpois(4,9), AD5_1= rpois(4,10), AD5_2= rpois(4,9), AD6_1= rpois(4,10), AD6_2= rpois(4,9)) Suppose I have data that looks like this. I wish to calculate the difference for each AD, paired with underscored number, i.e., AD1diff, AD2diff,AD3diff. Instead of writing

How to center line in ggplot2::geom_step() similar to highcharter

南楼画角 提交于 2021-02-10 14:37:56
问题 For my plot, I would like the ggplot2::geom_step() line alignment to be centered around my points, instead of aligned to the left In highcharter::hc_add_series(type = "line") there is an option called step = "center" . See my jsfiddle for the look I am going for in ggplot2 . library(ggplot2) #> Warning: package 'ggplot2' was built under R version 3.5.1 my_data <- data.frame( x = c("2015-06", "2015-07", "2015-08", "2015-09", "2015-10", "2015-11", "2015-12", "2016"), y = c(35, 41, 40, 45, 56,

How to center line in ggplot2::geom_step() similar to highcharter

青春壹個敷衍的年華 提交于 2021-02-10 14:37:21
问题 For my plot, I would like the ggplot2::geom_step() line alignment to be centered around my points, instead of aligned to the left In highcharter::hc_add_series(type = "line") there is an option called step = "center" . See my jsfiddle for the look I am going for in ggplot2 . library(ggplot2) #> Warning: package 'ggplot2' was built under R version 3.5.1 my_data <- data.frame( x = c("2015-06", "2015-07", "2015-08", "2015-09", "2015-10", "2015-11", "2015-12", "2016"), y = c(35, 41, 40, 45, 56,

Troubles with encoding, pattern matching and noisy texts in R

谁说胖子不能爱 提交于 2021-02-10 14:36:56
问题 We are experiencing problems with encoding, pattern matching using texts automatically downloaded from the web. We need some help to understand where the problem lies and how to fix it. Personally, I must confess that after having read so many posts on the topic, I am completely confused :-) Our texts sometimes include: 1) disturbing Unicode (I have read this already (Automatically escape unicode characters ), but I am not sure in which way it can help with regular expressions) 2) weird

How to count observations with certain value in a group conditionally?

独自空忆成欢 提交于 2021-02-10 14:33:26
问题 I am working with the following data frame: Year Month Day X Y Color 2018 January 1 4.5 6 Red 2018 January 4 3.2 8.1 Red 2018 January 11 1.1 2.3 Blue 2018 February 7 5.4 2.2 Blue 2018 February 15 1.5 4.4 Red 2019 January 3 8.6 2.3 Red 2019 January 22 1.1 2.5 Blue 2019 January 23 5.5 7.8 Red 2019 February 5 6.9 1.1 Red 2019 February 10 1.8 1.3 Red I am looking to create a new column that indicates the number of observations where x is greater than y and the color is 'red' for a given month.

How to substract multiple column based on condition in R

旧城冷巷雨未停 提交于 2021-02-10 14:32:32
问题 In my new dataset, I want to subtract the interest column(s) with interestpaid column(s) and interestunpaid column(s). For example, if there is 3 interest column and 2 interestpaid column and 2 interestunpaid column then the first interest column must be subtracted from the first interestpaid column and interestunpaid column, 2nd with 2nd and 3rd with 3rd. The last remaining 1 interest columns must be as it is. interest1 interest2 interest3 interestpaid1 interestpaid2 interestunpaid1

aproxfun function from binsmooth package, find x from y value

女生的网名这么多〃 提交于 2021-02-10 14:31:03
问题 I have created an approxfun function from the Binsmooth package for finding means from binned data. binedges <- c(10000,15000,20000,25000,30000,35000,40000,45000, 50000,60000,75000,100000,125000,150000,200000,NA) bincounts <- c(157532,97369,102673,100888,90835,94191,87688,90481, 79816,153581,195430,240948,155139,9452,92166,103217) splb <- splinebins(binedges, bincounts, 76091) typing splb$splineCDF(x) will return y, but I want to find the median value. I understand that this function is

How to filter rows with multiple conditions

余生长醉 提交于 2021-02-10 14:29:41
问题 I am new to R. I'm trying to filter rows from a data.frame (df) based on multiple conditions: An example of my data.frame: image of my df df: SNPA SNPB value block1 block2 score_T A1 A22 0.379927 A1|A2|A3|A4|A5|A6 A22|A23|A24|A25 12 A2 A23 0.449074 A1|A2|A3|A4|A5|A6 A22|A23|A24|A25 25 A3 A24 0.464135 A1|A2|A3|A4|A5|A6 A22|A23|A24|A25 584 A4 A22 0.328866 A1|A2|A3|A4|A5|A6 A22|A23|A24|A25 51 A5 A22 0.326026 A1|A2|A3|A4|A5|A6 A22|A23|A24|A25 64 A22 A27 0.57169 A22|A23|A24|A25 A27|A28|A29|A30|A31