reshape

Reshape Panel Data Wide Format to Long Format

此生再无相见时 提交于 2020-01-13 10:07:12
问题 I am struggling with transformation of a Panel Dataset from wide to long format. The Dataset looks like this: ID | KP1_430a | KP1_430b | KP1_430c | KP2_430a | KP2_430b | KP2_430c | KP1_1500a | ... 1 .... 2 .... KP1; KP2 up to KP7 describe the Waves. a,b up to f describe a specific Item. (E.g. left to right right placement of Party a) I would like to have this data in long format. Like this: ID | Party | Wave | 430 | 1500 1 1 1 .. .. 1 2 1 .. .. . . . 1 1 2 .. .. . . . 2 1 1 .. .. I tried to

Reshape package masking preventing melt from naming columns

谁说胖子不能爱 提交于 2020-01-12 22:30:50
问题 I have a script which requires both reshape and reshape2 libraries. I know this is poor practise, but I think plyr (or another library I am using) Vennerable is loading reshape and I have personally used reshape2 in a lot of places. The problem is that the masking of reshape2 by reshape is causing problems for the melt function # Example data frame df <- data.frame(id=c(1:5), a=c(rnorm(5)), b=c(rnorm(5))) # With just reshape2, variable and value columns are labelled correctly library(reshape2

Removing duplicate rows from data frame in R

本秂侑毒 提交于 2020-01-10 04:26:07
问题 I have two columns, would like to retain only the non commutative rows.For the data below my output should contain one combination of (1 2). i.e. for my query (1 2) is same as (2 1). Is there a simple way to do it in R. Already tried transposing. and retaining the upper traingular matrix. but it becomes a pain re transposing back the data. A B prob 1 2 0.1 1 3 0.2 1 4 0.3 2 1 0.3 2 3 0.1 2 4 0.4 My final output should be: A B prob 1 2 0.1 1 3 0.2 1 4 0.3 2 3 0.1 2 4 0.4 回答1: We can use data

Reshape Data Long to Wide - understanding reshape parameters

久未见 提交于 2020-01-09 05:32:25
问题 I have a long format dataframe dogs that I'm trying to reformat to wide using the reshape() function. It currently looks like so: dogid month year trainingtype home school timeincomp 12345 1 2014 1 1 1 340 12345 2 2014 1 1 1 360 31323 12 2015 2 7 3 440 31323 1 2014 1 7 3 500 31323 2 2014 1 7 3 520 The dogid column is a bunch of ids, one for each dog. The month column varies for 1 to 12 for the 12 months, and year from 2014 to 2015. Trainingtype varies for 1 to 2. Each dog has a timeincomp

How to getRange in all cell appear when reshape data for wide to long form by monthly columns name GooglespreadSheet

╄→尐↘猪︶ㄣ 提交于 2020-01-07 09:25:16
问题 In R , data.table library dcast() can transform dataset from wide to long shape ,how can i do this in googlespreadsheet? Sheet1 Name Type YTD JAN FEB MAR Product 1 A 8 1 3 4 Product 2 B 519 41 23 455 Product 3 C 32 2 25 5 NA D 3 NA 2 1 Sheet2 A B C D E F 1 Name Type YTD JAN FEB MAR 2 =filter(Sheet1!A2:F5,not(isblank(Sheet1!A2:A5))) Show reshaped data in Sheet3 from A1 [ ** C column for YTD is not necessarily needed . Adjusted script by me not works : from Tanaike function myFunction() { var

reshape2 melt not producing all pairs

牧云@^-^@ 提交于 2020-01-07 03:48:04
问题 I have a 332 x 332 distance matrix with distances between all possible pairs of stations. I need to transform this matrix into a data.frame with three columns - start.id, end.id, and distance. I have tried the melt function from the reshape2 package but this is not giving the right result Here is a snippet of the data mat 72 79 82 83 116 119 120 127 128 137 143 144 146 147 150 151 152 153 157 160 161 72 NA 6.43 7.458 11.546 3.784 10.252 12.780 4.835 5.230 2.168 10.614 9.806 7.058 6.533 7.117

converting rows to columns of a data frame in R

旧巷老猫 提交于 2020-01-06 19:32:06
问题 I have a data set like this movieID title year country genre directorName Rating actorName1 actorName.2 1 hello 1995 USA action john smith 6 tom hanks charlie sheen 2 MI2 1997 USA action mad max 8 tom cruize some_body 3 MI2 1997 USA thriller mad max 8 tom cruize some_body basically there are numerous rows that just have a different user given genre that I would like to columns having genre1, genre2, ... I tried reshape() but it would only convert based on some ID variable. If anyone has any

How to increase sample frequency of dataset (reshape, interpolate?) and fill the Nan values with means

北城余情 提交于 2020-01-06 04:54:14
问题 I have a dataset with an uneven sample frequency as seen on this subset: time date x y id nn1 nn2 0 2019-09-17 08:43:06 234 236 4909 22.02271554554524 38.2099463490856 0 2019-09-17 08:43:06 251 222 4911 22.02271554554524 46.57252408878007 1 2019-09-17 08:43:07 231 244 4909 30.4138126514911 41.617304093369626 1 2019-09-17 08:43:07 252 222 4911 30.4138126514911 46.57252408878007 1 2019-09-17 08:43:07 207 210 4900 41.617304093369626 46.57252408878007 2 2019-09-17 08:43:08 234 250 4909 33

Melt data for one column

99封情书 提交于 2020-01-05 20:52:06
问题 I have this data: datetime stock 2010-01-01 4 2010-01-02 7 2010-01-03 2 2010-01-04 9 And I want to make this output: datetime stock val 2010-01-01 4 stock 2010-01-02 7 stock 2010-01-03 2 stock 2010-01-04 9 stock I tried to melt the data but it didn't work. Any suggestions? 回答1: I don't know what you tried, but both of the following options work for me. Assuming your data.frame is called "mydf": Option 1: stack from Base R cbind(mydf[1], stack(mydf[-1])) # datetime values ind # 1 2010-01-01 4

Extracting data from data frame

拜拜、爱过 提交于 2020-01-05 08:37:51
问题 I have a data frame that looks like this: Code ID X1 X2 1 1000 2 1.6 250.6 2 1000 3 0.15 340.9 3 1001 2 0.53 441.7 4 1001 3 1.8 499.0 5 1002 2 4.4 516.6 6 1003 3 4.9 616.6 What I would like to do is to create a new data frame with unique codes and each unique ID as a column (there are two unique IDs:2 and 3), with the corresponding X1 and X2 values, so the result should look like this: Code ID2X1 ID2X2 ID3X1 ID3X2 1 1000 1.6 250.6 0.15 340.9 2 1001 0.53 441.7 1.8 499.0 5 1002 4.4 516.6 NA NA