tidyverse

Replace part of string with mutate (in a pipe)

旧街凉风 提交于 2020-08-27 07:52:31
问题 I would like to replace a part of a string (between the first 2 underscores, the first group always being "i") like in the base R example below: library(dplyr) library(stringr) d <- tibble(txt = c("i_0000_GES", "i_0000_OISO", "i_0000_ASE1333"), repl = c("1111", "1111", "2222")) str_sub(d$txt, 3, 6) <- d$repl d # A tibble: 3 x 2 # txt repl # <chr> <chr> # 1 i_1111_GES 1111 # 2 i_1111_OISO 1111 # 3 i_2222_ASE1333 2222 How can I do that either using str_sub<- or another stringr-function? 回答1:

extracting city and state information from a google street address

China☆狼群 提交于 2020-08-25 06:56:38
问题 I have a data set that contained lat/long information for different point locations, and I would like to know which city and state are associated with each point. Following this example I used the revgeocode function from ggmap to obtain a street address for each location, producing the data frame below: df <- structure(list(PointID = c(1787L, 2805L, 3025L, 3027L, 3028L, 3029L, 3030L, 3031L, 3033L), Latitude = c(38.36648102, 36.19548585, 43.419774, 43.437222, 43.454722, 43.452643, 43.411949,

extracting city and state information from a google street address

岁酱吖の 提交于 2020-08-25 06:56:07
问题 I have a data set that contained lat/long information for different point locations, and I would like to know which city and state are associated with each point. Following this example I used the revgeocode function from ggmap to obtain a street address for each location, producing the data frame below: df <- structure(list(PointID = c(1787L, 2805L, 3025L, 3027L, 3028L, 3029L, 3030L, 3031L, 3033L), Latitude = c(38.36648102, 36.19548585, 43.419774, 43.437222, 43.454722, 43.452643, 43.411949,

How to calculate ratios and normalized ratios in all possible combinations in R?

陌路散爱 提交于 2020-08-10 19:18:39
问题 I want to calculate normalised ratios and simple ratios in all possible combinations in R. This is the sample dataset df = structure(list(var_1 = c(0.035, 0.047, 0.004, 0.011, 0.01, 0.01, 0.024), var_2 = c(0.034, 0.047, 0.004, 0.012, 0.01, 0.011, 0.025 ), var_3 = c(0.034, 0.047, 0.006, 0.013, 0.011, 0.013, 0.026), var_4 = c(0.034, 0.046, 0.008, 0.016, 0.014, 0.015, 0.028 ), var_5 = c(0.034, 0.046, 0.009, 0.017, 0.015, 0.016, 0.029 )), class = "data.frame", row.names = c(NA, -7L)) I could able