melt

Separate values in a column of a dataframe and melt

江枫思渺然 提交于 2019-12-02 13:36:50
问题 I have a data frame where I want to separate values in the Client.ID column and melt, so each row contains one Client.ID and and the corresponding Account.Name and owner. > head(df) Account.Owner Account.Name Client.ID 1 Deb Berman Albertsons LLC 3184, 3186, 3185, 2578 2 Deb Berman All Recipes 909, 4937 3 Liz Madsen American Express 1230,1236 4 Deb Berman Bed Bath & Beyond 1180, 1556 5 Deb Berman Birchbox 101, 1704, 5149, 5150, 5148 6 Jeff Murphy Brown Shoe Company 5402, 6159, 6160 At the end

R - Reshape - Melt Error

吃可爱长大的小学妹 提交于 2019-12-02 10:45:30
I am trying to melt a data frame and I get this weird error. Any ideas why? str(zx7) 'data.frame': 519 obs. of 5 variables: $ calday.new: Date, format: "2011-01-03" "2011-01-04" "2011-01-05" "2011-01-06" ... $ A20 : Time-Series from 1 to 519: 0 0 0 0 0 0 0 0 0 0 ... $ B20 : Time-Series from 1 to 519: 0 0 0 0 0 0 0 0 0 0 ... $ C20 : Time-Series from 1 to 519: 0 0 0 0 0 0 0 0 0 0 ... $ D20 : Time-Series from 1 to 519: 0 0 0 0 0 0 0 0 0 0 ... zx7.melt <- melt(zx7, id=c("calday.new")) Error in `[<-.ts`(`*tmp*`, ri, value = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, : only replacement of elements is allowed I

Separate values in a column of a dataframe and melt

房东的猫 提交于 2019-12-02 07:25:24
I have a data frame where I want to separate values in the Client.ID column and melt, so each row contains one Client.ID and and the corresponding Account.Name and owner. > head(df) Account.Owner Account.Name Client.ID 1 Deb Berman Albertsons LLC 3184, 3186, 3185, 2578 2 Deb Berman All Recipes 909, 4937 3 Liz Madsen American Express 1230,1236 4 Deb Berman Bed Bath & Beyond 1180, 1556 5 Deb Berman Birchbox 101, 1704, 5149, 5150, 5148 6 Jeff Murphy Brown Shoe Company 5402, 6159, 6160 At the end I want it to look like so Account.Owner Account.Name Client.ID 1 Deb Berman Albertsons LLC 3184 2 Deb

R: Converting wide format to long format with multiple 3 time period variables [duplicate]

心不动则不痛 提交于 2019-12-02 07:24:19
问题 This question already has answers here : Reshaping multiple sets of measurement columns (wide format) into single columns (long format) (7 answers) Closed last year . Apologies if this is a simple question, but I haven't been able to find a simple solution after searching. I'm fairly new to R, and am having trouble converting wide format to long format using either the melt (reshape2) or gather(tidyr) functions. The dataset that I'm working with contains 22 different time variables that are

R - Plot multiple columns as years on x-axis, plot rows as different lines

天涯浪子 提交于 2019-12-02 06:48:42
问题 Here's my data frame: 2010 2011 2012 2013 2014 2015 A 0 100 164 75 154 110 B 71 77 136 58 138 136 C 0 0 132 53 83 0 I'd like to make a line graph in which the years are plotted along the x-axis and and counts are plotted along the y-axis, with rows A, B, and C each having their own line. Is it possible to do this without melting the years into a single variable? 回答1: There is a function for this, matplot . Try matplot(yourData, type="l") 来源: https://stackoverflow.com/questions/32254821/r-plot

R - Plot multiple columns as years on x-axis, plot rows as different lines

烂漫一生 提交于 2019-12-02 04:38:27
Here's my data frame: 2010 2011 2012 2013 2014 2015 A 0 100 164 75 154 110 B 71 77 136 58 138 136 C 0 0 132 53 83 0 I'd like to make a line graph in which the years are plotted along the x-axis and and counts are plotted along the y-axis, with rows A, B, and C each having their own line. Is it possible to do this without melting the years into a single variable? There is a function for this, matplot . Try matplot(yourData, type="l") 来源: https://stackoverflow.com/questions/32254821/r-plot-multiple-columns-as-years-on-x-axis-plot-rows-as-different-lines

R: Converting wide format to long format with multiple 3 time period variables [duplicate]

那年仲夏 提交于 2019-12-02 04:14:54
This question already has an answer here: Reshaping multiple sets of measurement columns (wide format) into single columns (long format) 7 answers Apologies if this is a simple question, but I haven't been able to find a simple solution after searching. I'm fairly new to R, and am having trouble converting wide format to long format using either the melt (reshape2) or gather(tidyr) functions. The dataset that I'm working with contains 22 different time variables that are each 3 time periods. The problem occurs when I try to convert all of these from wide to long format at once. I have had

R: Melt and Dcast

北城余情 提交于 2019-12-02 04:03:36
I have a dataset like this: CASE_ID = c("C1","C1", "C2","C2", "C2", "C3", "C4") PERSON_ID = c(1,0,7,8,1,20,7) PERSON_DIVISION = c("Zone 1", "NA", "Zone 1", "Zone 3", "Zone 1", "Zone 5", "Zone 1") df <- data.frame(CASE_ID, PERSON_ID, PERSON_DIVISION) df That results in: CASE_ID PERSON_ID PERSON_DIVISION 1 C1 1 Zone 1 2 C1 0 NA 3 C2 7 Zone 1 4 C2 8 Zone 3 5 C2 1 Zone 1 6 C3 20 Zone 5 7 C4 7 Zone 1 And I want to transform it in: CASE_ID P1_ID P2_ID P3_ID P1_Division P2_Division P3_Division 1 1 0 NA Zone 1 NA NA 2 7 8 1 Zone 1 Zone 3 Zone 1 3 20 NA NA Zone 5 NA NA 4 7 NA NA Zone 1 NA NA My

From long to wide form without id.var?

允我心安 提交于 2019-12-02 02:40:06
问题 I have some data in long form that looks like this: dat1 = data.frame( id = rep(LETTERS[1:2], each=4), value = 1:8 ) In table form: id value A 1 A 2 A 3 A 4 B 5 B 6 B 7 B 8 And I want it to be in short form and look like this: dat1 = data.frame(A = 1:4, B = 5:8) In table form: A B 1 5 2 6 3 7 4 8 Now I could solve this by looping with cbind() and stuff, but I want to use some kind of reshape/melt function as these are the best way to do this kind of thing I think. However, from spending >30

From long to wide form without id.var?

↘锁芯ラ 提交于 2019-12-02 01:20:54
I have some data in long form that looks like this: dat1 = data.frame( id = rep(LETTERS[1:2], each=4), value = 1:8 ) In table form: id value A 1 A 2 A 3 A 4 B 5 B 6 B 7 B 8 And I want it to be in short form and look like this: dat1 = data.frame(A = 1:4, B = 5:8) In table form: A B 1 5 2 6 3 7 4 8 Now I could solve this by looping with cbind() and stuff, but I want to use some kind of reshape/melt function as these are the best way to do this kind of thing I think. However, from spending >30 minutes trying to get melt() and reshape() to work, reading answers on SO, it seems that these functions