spread

Issue creating better random algorithm - daily spread

旧城冷巷雨未停 提交于 2019-12-25 08:33:50
问题 i need a algoritm that spreads some numbers across a day in percentages, following min / max percentage for that time rule, this is what i have atm: public function getSpread() { $rules = [ '00-07' => ['min' => 5, 'max' => 10], '08-12' => ['min' => 20, 'max' => 30], '13-16' => ['min' => 20, 'max' => 30], '17-22' => ['min' => 25, 'max' => 40], '23-24' => ['min' => 10, 'max' => 15], ]; $spread = []; foreach ($rules as $time => $rule) { $value = rand($rule['min'], $rule['max']); while ($this-

R - tidyr - spread() - dealing with NA as column name

孤街醉人 提交于 2019-12-24 16:03:04
问题 I am spreading multiple categorical variables to Boolean columns using tidyr::spread() . As the data contains NAs, spread creates a new column without a name. What I'm looking for is a way to get rid off the NAs using a) a piping solution (I've tried select_() and '['() , but don't know how to refer to the NA column's name or index) or b) a custom function, which would be even better c) a way to simply not generate the NA columns, Hadleyverse compatible, if possible. Below is my current (and

Elegant solution for casting (spreading) multiple columns of character vectors

限于喜欢 提交于 2019-12-24 09:29:11
问题 I want to transforms a data frame with contact information with of a for a list of municipalities in which similar information such as e.g. phone number appears in multiple columns. I have tried using both reshape2::dcast() as well as tidyr::spread() , neither of which solves my problem. I have also checked other post of stack overflow e.g. Multiple column spread Have yet to find a solution which works. It seems to me that the problems should be fairly straightforward (and solvable with

How can I spread a data frame (from long to wide) and preserve two fields' data?

本小妞迷上赌 提交于 2019-12-14 03:25:09
问题 I have a data frame: df <- structure(list(date = structure(c(17563, 17563, 17563, 17563, 17563, 17563, 17563, 17563, 17563, 17563, 17563, 17563, 17563, 17563, 17563, 17563, 17563, 17563, 17563, 17563, 17563, 17563, 17563, 17563, 17564, 17564, 17564, 17564, 17564, 17564, 17564, 17564, 17564, 17564, 17564, 17564, 17564, 17564, 17564, 17564, 17564, 17564, 17564, 17564, 17564, 17564, 17564, 17564, 17565, 17565, 17565, 17565, 17565, 17565, 17565, 17565, 17565, 17565, 17565, 17565, 17565, 17565,

Transpose dplyr::tbl object

99封情书 提交于 2019-12-13 17:52:32
问题 I am using src_postgres to connect and dplyr::tbl function to fetch data from redshift database. I have applied some filters and top function to it using the dplyr itself. Now my data looks as below: riid day hour <dbl> <chr> <chr> 1 5542. "THURSDAY " 12 2 5862. "FRIDAY " 15 3 5982. "TUESDAY " 15 4 6022. WEDNESDAY 16 My final output should be as below: riid MON TUES WED THUR FRI SAT SUN 5542 12 5862 15 5988 15 6022 16 I have tried spread. It throws the below error because of the class type:

Multiple column spread

天大地大妈咪最大 提交于 2019-12-13 10:06:15
问题 I have a need to do what is really what tidyr::spread() does, but for multiple value columns. If I have a data set like this: te <- structure(list(Syllable = c("[pa]", "[ta]", "[ka]", "[pa]", "[ta]", "[ka]", "[pa]", "[ta]", "[ka]", "[pa]"), PA = c(15.9252335141423, 2.17504491982172, 5.26727958979289, 4.48590068583509, 2.1316282072803e-13, 14.1415335887116, 3.51720477328246, 0.839953301362556, 5.74712643678048, 7.01396701583887), transient_mean = c(4.43699436235785, 4.8733556527069, 5

Fill count/sum based on previous row count over time series

给你一囗甜甜゛ 提交于 2019-12-13 03:56:20
问题 I have performed counts of events (in Group 1) over a time period for each group (in Group 2). I am looking to spread Group 1 events into separate columns, and using Group 2 and timestamp as rows. Each cell will contain the counts of events over a time period (Present date to the previous 4 days). See the example below, for each of the Group 2 (I & II) I counted Events A and L in Group 1 happened within 4 days. dates = as.Date(c("2011-10-09", "2011-10-15", "2011-10-16", "2011-10-18", "2011-10

could not find function “spread” [closed]

情到浓时终转凉″ 提交于 2019-12-11 16:35:13
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . So at the moment I am trying to figure out how to build a movie recommender system from MovieLense (https://grouplens.org/datasets/movielens/100k/). I read some instructions from a tutorial. library(dplyr) library(recommenderlab) library(magrittr) data <- read.table("u.data", header = F, stringsAsFactors = T)

How do I use spread and group_by on a single row dataset

末鹿安然 提交于 2019-12-11 13:27:10
问题 I have a form dataframe that has multiple entries for same IDs and dates . I need to group this dataset to a single row, but I have some problems with the use of gather, spread and group. # surveys dataset user_id <- c(100, 100, 100, 200, 200, 200) int_id <- c(1000, 1000, 1000, 2000, 2000, 2000) fech <- c('01/01/2019', '01/01/2019','01/01/2019','02/01/2019','02/01/2019','02/01/2019') order <- c(1,2,3,1,2,3) questions <- c('question1','question2','question3','question1','question2','question3'

Confusion with Spread in tidyr

℡╲_俬逩灬. 提交于 2019-12-11 07:27:31
问题 I have a dataframe as follows: ddd <- structure(list(sample_date = structure(c(1400612280, 1400612280, 1400612280, 1400612280, 1400612280, 1400612280, 1400616420, 1400616420, 1400616420, 1400616420, 1400616420, 1400616420, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780, 1400604780