reshape2

R: How to get something like adjacency matrix, but on the intersection value of third column? [closed]

隐身守侯 提交于 2019-12-13 04:39:41
问题 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 6 years ago . I have data frame like this: V1 V2 LABEL 1 83965 891552 A 2 88599 891552 B 3 42966 891552 C 4 83965 891553 D 5 88599 891553 D 6 42966 891553 B How can I convert it to something like adjacency matrix, but on the intersection of colum-row i would like to have, the third colum value, like that: 891552 891553 42966

Reshape data in R change a long table into a wide table

╄→гoц情女王★ 提交于 2019-12-13 04:35:42
问题 I would like to use the reshape2 package in R to change my long table into a wide table. I have a data set from database which is like this (example): id1 | id2 | info | action_time | 1 | a | info1 | time1 | 1 | a | info1 | time2 | 1 | a | info1 | time3 | 2 | b | info2 | time4 | 2 | b | info2 | time5 | And now I want it to be like this: id1 | id2 | info |action_time 1|action_time 2|action_time 3| 1 | a | info1 | time1 | time2 | time3 | 2 | b | info2 | time4 | time5 | | I have tried several

How to use dcast function to transform my dataset

荒凉一梦 提交于 2019-12-13 03:47:54
问题 I have a very big dataset. It consist more than 10 million records. It is very difficult to use this much of dataset to apply any algorithm. So, that I trying to restructure this dataset. In my dataset, so many records are there per one customer. Now I am trying to convert one record per one customer. Here I am representing my sample mock up data. d1<-structure( list(userid = c(64455670203, 64455670203, 64455670203, 64455670203, 64455670203, 64455670204, 64455670204, 64455670204, 64455670204,

Removing incomplete cases from output of tidyr - gather() - r

ⅰ亾dé卋堺 提交于 2019-12-13 02:06:37
问题 I have untidy data in a dataframe that looks like this. Here you can see in 'team' the names of some soccer teams. Name1-3 are variable listing the different names used to refer to these teams in the first column. team name1 name2 name3 1 Loughborough Loughborough 2 Luton Town Luton Town Luton 3 Macclesfield Macclesfield 4 Maidstone United Maidstone United 5 Manchester City Manchester City Man City 6 Manchester United Manchester United Newton Heath Man United 7 Mansfield Town Mansfield Town

reshape2 dcast without aggregation - problems with seq

拟墨画扇 提交于 2019-12-12 16:06:52
问题 I try to reshape a dataset from this (mydata - snippet) sample species cell_nr biovol 1 41442bay_1 Mytilus sp. 6.22 1243.04 2 41502elba_1 Mytilus sp. 1.35 260.64 3 41502bay_3 Mytilus sp. 2.74 548.21 4 41443bay_2 M. edulis 599.14 114028.15 5 41411elba_2 M. edulis 5107.51 1021502.16 to this (result) sample variable Mytilus sp. M. edulis 1 41442bay_1 cell_nr 6.22 0 2 41442bay_1 biovol 1243.04 0 3 41443bay_2 cell_nr 0 599.14 4 41443bay_2 biovol 0 114028.15 So far I used reshape2 in R mymelt <-

In R transpose and combine multiple dataframes with missing data and blank column names / rename melted columns prior to dcast

北慕城南 提交于 2019-12-12 03:18:56
问题 I have searched and found many solutions that came close, but never quite worked in the end. This is probably something very simple, for those with experience... Here is a snippet of my data. This was created automatically from a JSON import by the package jsonlite. The data is very nicely structured, but I am nevertheless helpless. Update2: I have added the relevant data below structure(list(rightsize = c(42L, 50L, 52L, 49L, 41L, 41L, 41L, 41L, 41L, 45L, 47L, 42L, 45L, 46L, 42L, 44L, 44L,

how to transform this dataframe to long format

北城以北 提交于 2019-12-11 19:07:06
问题 I have a dataframe looking like this: a <- c("Lilo","Chops","Henmans") a <- cbind(a,c(0.1,0.5,0.25),c(0.2,0.3,0.65),c(0.7,0.2,0.1)) colnames(a) <- c("market","Product A","Product B","Product C") and would like to melt it: b <- melt(a, varnames = c("market")) this gives the following: > b market NA value 1 1 market Lilo 2 2 market Chops 3 3 market Henmans 4 1 Product A 0.1 5 2 Product A 0.5 6 3 Product A 0.25 7 1 Product B 0.2 8 2 Product B 0.3 9 3 Product B 0.65 10 1 Product C 0.7 11 2

dcast changes content of dataframe

江枫思渺然 提交于 2019-12-11 13:57:58
问题 I tried using the reshape package to reshape a dataframe I got, but when using it, numbers in the dataframe are changed which should not be. The dataframe contains several variables as well as multiple times these variables have been measured, for each person there are 6 rows, that is 6 times that person has been measured. Now I want to reshape the dataframe so there is only one row for each person instead of 6, that means every variable should be there 6 times (once for every measurement),

Reshape DF from long to wide in R using Reshape2 without an aggregation function

懵懂的女人 提交于 2019-12-11 10:13:24
问题 a common task in the data I work with is reshaping client data from long to wide. I have a process to do this with Reshape outlined below that basically creates new (but unmodified) columns with a numeric index appended. In my case I do not want to perform any modifications on the data. My question, because I often use reshape2 for other operations, is how this can be accomplished with dcast? It does not seem that the example data need to be melted by id, for example, but I'm not sure how I

Turn long dataset of classes taken into wide dataset where variables are dummy code for each class

妖精的绣舞 提交于 2019-12-11 08:00:01
问题 Say I have a dataset where rows are classes people took: attendance <- data.frame(id = c(1, 1, 1, 2, 2), class = c("Math", "English", "Math", "Reading", "Math")) I.e., id class 1 1 "Math" 2 1 "English" 3 1 "Math" 4 2 "Reading" 5 2 "Math" And I want to create a new dataset where rows are ids and the variables are class names, like this: class.names <- names(table(attendance$class)) attedance2 <- matrix(nrow=length(table(attendance$id)), ncol=length(class.names)) colnames(attedance2) <- class