spread

How to copy grouped rows into column by dplyr/tidyverse in R?

末鹿安然 提交于 2019-12-11 03:13:33
问题 I am trying to copy sets of rows into columns using dplyr. Following is my data frame. df <- data.frame( hid=c(1,1,1,1,2,2,2,2,2,3,3,3,3), mid=c(1,2,3,4,1,2,3,4,5,1,2,3,4), tmid=c("010","01010","010","01020", "010","0120","010","010","020", "010","01010","010","01020"), thid=c("010","02020","010","02020", "000","0120","010","010","010", "010","02020","010","02020"), ) It is printed in the following format: > df hid mid tmid thid 1 1 1 010 010 2 1 2 01010 02020 3 1 3 010 010 4 1 4 01020 02020

Trouble pivoting in pandas (spread in R)

北城余情 提交于 2019-12-10 04:10:23
问题 I'm having some issues with the pd.pivot() or pivot_table() functions in pandas. I have this: df = pd.DataFrame({'site_id': {0: 'a', 1: 'a', 2: 'b', 3: 'b', 4: 'c', 5: 'c',6: 'a', 7: 'a', 8: 'b', 9: 'b', 10: 'c', 11: 'c'}, 'dt': {0: 1, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1,6: 2, 7: 2, 8: 2, 9: 2, 10: 2, 11: 2}, 'eu': {0: 'FGE', 1: 'WSH', 2: 'FGE', 3: 'WSH', 4: 'FGE', 5: 'WSH',6: 'FGE', 7: 'WSH', 8: 'FGE', 9: 'WSH', 10: 'FGE', 11: 'WSH'}, 'kw': {0: '8', 1: '5', 2: '3', 3: '7', 4: '1', 5: '5',6: '2', 7:

R: spread function on data frame with duplicates

Deadly 提交于 2019-12-09 03:43:01
问题 I have a data frame that I need to pivot but the data frame has duplicate identifiers, so spread function gives an error Error: Duplicate identifiers for rows (5, 6) Dimension = c("A","A","B","B","A","A") Date = c("Mon","Tue","Mon","Wed","Fri","Fri") Metric = c(23,25,7,9,7,8) df = data.frame(Dimension,Date,Metric) df Dimension Date Metric 1 A Mon 23 2 A Tue 25 3 B Mon 7 4 B Wed 9 5 A Fri 7 6 A Fri 8 library(tidyr) df1 = spread(df, Date, Metric, fill = " ") Error: Duplicate identifiers for

Can spread() in tidyr spread across multiple value?

妖精的绣舞 提交于 2019-12-08 06:09:48
问题 I am using the iris data set, first, I did some manipulation with that data set and make it into the following form D1 = iris[,c(1,2,5)] D2 = iris[,c(3,4,5)] colnames(D1)[1:2] = c('Length','Width') colnames(D2)[1:2] = c('Length','Width') D1 = D1 %>% mutate(Part = 'Sepal') D2 = D2 %>% mutate(Part = 'Petal') D = rbind(D2,D1) which looks like Species Part Length Width 1 setosa Petal 1.4 0.2 2 setosa Petal 1.4 0.2 3 setosa Petal 1.3 0.2 4 setosa Petal 1.5 0.2 5 setosa Petal 1.4 0.2 6 setosa Petal

Browser support for text-shadow spread value

大兔子大兔子 提交于 2019-12-07 19:17:09
问题 Seen discussions here but it has been 2 years! I don't know if I'm using this right but I have the following sass/compass code: +text-shadow(red 0 3px 0 3px) Generating the following css : text-shadow: red 0 3px 3px, red 0 3px 0 3px; text-shadow: red 0 3px 0 3px, red 0 3px 0 3px; Which not works in neither Chrome/Safari/Firefox/Opera. Is this something with the declaration or this spread feature was really removed from specs? 回答1: It says in the specs that, This property accepts a comma

Browser support for text-shadow spread value

只谈情不闲聊 提交于 2019-12-06 07:53:12
Seen discussions here but it has been 2 years! I don't know if I'm using this right but I have the following sass/compass code: +text-shadow(red 0 3px 0 3px) Generating the following css : text-shadow: red 0 3px 3px, red 0 3px 0 3px; text-shadow: red 0 3px 0 3px, red 0 3px 0 3px; Which not works in neither Chrome/Safari/Firefox/Opera. Is this something with the declaration or this spread feature was really removed from specs? It says in the specs that, This property accepts a comma-separated list of shadow effects to be applied to the text of the element. Values are interpreted as for ‘box

python pandas pivot: How to do a proper tidyr-like spread?

百般思念 提交于 2019-12-06 05:01:12
I am missing spontaneous and easy conversion from long to wide and vice versa in Python. Imagine, I have a large tidy dataframe with a lot of property-columns and a single column that contains all the actual values like PropA ... PropZ Value green Saturn 400 green Venus 3 red Venus 2 . . The data itself is very nicely handled by keeping it tidy. But sometimes I have to perform some actions across certain properties (for instance it might be interesting to compare beeing red vs beeing green (for all the items that are similar w.r.t the other properties)). So the straight-forward way would be to

r tidyverse spread() using multiple key value pairs not collapsing rows

Deadly 提交于 2019-12-06 03:17:03
问题 I am trying to spread() a couple of key/value pairs but the common value column does not collapse. I think that it may have to do with some previous processing, or more likely I do not know the right way to spread two or more key/value pairs to get the result I expect. I'm starting with this data set: library(tidyverse) df <- tibble(order = 1:7, line_1 = c(23,8,21,45,68,31,24), line_2 = c(63,25,25,24,48,24,63), line_3 = c(62,12,10,56,67,25,35)) There are 2 pre-spread steps to define order of

Trouble pivoting in pandas (spread in R)

早过忘川 提交于 2019-12-05 04:26:24
I'm having some issues with the pd.pivot() or pivot_table() functions in pandas. I have this: df = pd.DataFrame({'site_id': {0: 'a', 1: 'a', 2: 'b', 3: 'b', 4: 'c', 5: 'c',6: 'a', 7: 'a', 8: 'b', 9: 'b', 10: 'c', 11: 'c'}, 'dt': {0: 1, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1,6: 2, 7: 2, 8: 2, 9: 2, 10: 2, 11: 2}, 'eu': {0: 'FGE', 1: 'WSH', 2: 'FGE', 3: 'WSH', 4: 'FGE', 5: 'WSH',6: 'FGE', 7: 'WSH', 8: 'FGE', 9: 'WSH', 10: 'FGE', 11: 'WSH'}, 'kw': {0: '8', 1: '5', 2: '3', 3: '7', 4: '1', 5: '5',6: '2', 7: '3', 8: '5', 9: '7', 10: '2', 11: '5'}}) df Out[140]: dt eu kw site_id 0 1 FGE 8 a 1 1 WSH 5 a 2 1 FGE

Using spread with duplicate identifiers for rows giving error

别等时光非礼了梦想. 提交于 2019-12-04 05:40:17
问题 My data looks like this: df <- read.table(header = T, text = "GeneID Gene_Name Species Paralogues Domains Functional_Diversity 1234 DDR1 hsapiens 14 2 8.597482 5678 CSNK1E celegans 70 4 8.154788 9104 FGF1 Chicken 3 0 5.455874 4575 FGF1 hsapiens 4 6 6.745845") I need it to look like: Gene_Name hsapiens celegans ggalus DDR1 8.597482 NA NA CSNK1E NA 8.154788 NA FGF1 6.745845 NA 5.455874 I've tried using: library(tidyverse) df %>% select(Gene_Name, Species, Functional_Diversity) %>% spread