reshape2

stacking/melting multiple columns into multiple columns in R

蓝咒 提交于 2019-12-24 11:19:15
问题 I am trying to melt/stack/gather multiple specific columns of a dataframe into 2 columns, retaining all the others. I have tried many, many answers on stackoverflow without success (some below). I basically have a situation similar to this post here: Reshaping multiple sets of measurement columns (wide format) into single columns (long format) only many more columns to retain and combine. It is important to mention my year columns are factors and I have many, many more columns than the sample

Can't install package reshape2 for R 2.15.3 on Ubuntu 12.04.4

大城市里の小女人 提交于 2019-12-24 06:37:48
问题 I am having trouble installing the reshape2 package for R 2.15.3 on Ubuntu 12.04.4 LTS. I decided not to upgrade to R 3.x because many of the packages that I use have not been upgraded to support the new version. When I try to install reshape2 using R 2.15.3 on Ubuntu 12.04.4 LTS, I get the following. > install.packages("reshape2") Installing package(s) into â/usr/local/lib/R/site-libraryâ (as âlibâ is unspecified) Warning in install.packages("reshape2") : 'lib = "/usr/local/lib/R/site

Reshape data using dcast?

眉间皱痕 提交于 2019-12-24 04:51:49
问题 I don't know if using dcast() is the right way, but I want to reshape the following data.frame: df <- data.frame(x=c("p1","p1","p2"),y=c("a","b","a"),z=c(14,14,16)) df x y z 1 p1 a 14 2 p1 b 14 3 p2 a 16 so that it looks like this one: df2 <- data.frame(x=c("p1","p2"),a=c(1,1),b=c(1,0),z=c(14,16)) x a b z 1 p1 1 1 14 2 p2 1 0 16 The variable y in df should be broken so that its elements are new variables, each dummy coded. All other variables (in this case just z ) are equal for each person

Why does reshape2 melt return value = NA for me?

岁酱吖の 提交于 2019-12-23 20:08:29
问题 Why does reshape2 melt return value = NA for me? It works for me with reshape, but not with reshape2: Here is an example datafile: "","station_id","year","month","day","h1","h2","h3","h4","h5","h6","h7","h8","h9","h10","h11","h12","h13","h14","h15","h16","h17","h18","h19","h20","h21","h22","h23","h24" "1",1,2004,1,1,46,46,45,41,39,35,33,33,36,47,53,54,55,55,55,55,52,46,40,40,39,38,40,41 "2",1,2004,1,2,43,44,46,46,47,47,47,47,47,47,47,49,52,56,54,56,57,53,50,47,46,45,45,45 "3",1,2004,1,3,45,46

Combining multiple rows into one row with multiple columns of data R

和自甴很熟 提交于 2019-12-23 12:52:07
问题 I have a dataset where the same effect was measured in different ways and I want to compare those measurements. My dataset looks like this: Study MType ID Insect Mean Sd N Alla Fecundity 1 Aphid .62 .7628 11 Alla RGR 1 Aphid -32.8 7.76 11 Ando Survival 2 Bee 2.34 .67 8 Ando RGR 2 Bee 4.56 .34 10 Ando Fecundity 2 Bee 5.32 4.3 20 I want to combine the rows by ID number so that the MType, Mean, Sd and N for each row are preserved (although the column names need to change so the columns are

how to create new variables from one variable using two rules

只谈情不闲聊 提交于 2019-12-23 05:59:57
问题 I would appreciate any help to create new variables from one variable. Specifically, I need help to simultaneously create one row per each ID and various columns of E , where each of the new columns of E , (that is, E1 , E2 , E3 ) contains the values of E for each row of ID . I tried doing this which melt followed by spread but I am getting the error: Error: Duplicate identifiers for rows (4, 7, 9), (1, 3, 6), (2, 5, 8) Additionally, I tried the solutions discussed here and here but these did

How to convert an object with melt keeping the row-column names?

纵饮孤独 提交于 2019-12-23 04:21:20
问题 I want to convert a dunn.test output with the melt function from the reshape2 package, but I lose the pairwise group names. How to keep them in the "melted" data frame? Using the melt for the pairwise.wilcox.test output, with the code: pw <- pairwise.wilcox.test(tabel2$RS.14_2, tabel2$lot, p.adj = "bonf") melt(pw[[3]]) outputs the next result: Var1 Var2 value 1 3StL 1StL NaN 2 IP 1StL 6,930275e-36 3 ISR 1StL 5,929457e-21 4 ISU 1StL 3,427444e-33 5 StM 1StL 1,506569e-06 6 3StL 3StL NA 7 IP 3StL

dcast efficiently large datasets with multiple variables

江枫思渺然 提交于 2019-12-23 00:24:32
问题 I am trying to dcast a large dataset (millions of rows). I have one row for arrival time and origin, and another row for departure time and destination. There is an id to identify the unit in both cases. It looks similar to this: id time movement origin dest 1 10/06/2011 15:54 ARR 15 15 1 10/06/2011 16:14 DEP 15 29 2 10/06/2011 17:59 ARR 73 73 2 10/06/2011 18:10 DEP 73 75 2 10/06/2011 21:10 ARR 75 75 2 10/06/2011 21:20 DEP 75 73 3 10/06/2011 17:14 ARR 17 17 3 10/06/2011 18:01 DEP 17 48 4 10

Reshape data frame from wide to long with re-occuring column names in R

。_饼干妹妹 提交于 2019-12-22 09:31:50
问题 I'm trying to convert a data frame from wide to long format using the melt formula. The challenge is that I have multiple column names that are labeled the same. When I use the melt function, it drops the values from the repeat column. I have read similar questions and it was advised to use the reshape function, however I was not able to get it work. To reproduce my starting data frame: conversion.id<-c("1", "2", "3") interaction.num<-c("1","1","1") interaction.num2<-c("2","2","2") conversion

Reorganizing data from 3 rows to 1

寵の児 提交于 2019-12-22 04:58:48
问题 I need to reorganize data from a csv file that contains mostly repeating data. I have the data imported into R in a dataframe but I am having trouble with the following: ID Language Author Keyword 12 eng Rob COLOR=Red 12 eng Rob SIZE=Large 12 eng Rob DD=1 15 eng John COLOR=Red 15 eng John SIZE=Medium 15 eng John DD=2 What I need to do is transform this into a row with each keyword in a separate column ID Language Author COLOR SIZE DD 12 eng Rob Red Large 1 Any ideas? 回答1: Using the reshape2