Questions tagged [reshape2]

The reshape2 package in R contains functions that allow data to be transformed into more convenient forms.

reshape2 is an package for flexibly restructuring and aggregating data. Its primary use is ing data between wide format with repeated measurements in separate columns of the same record and long format with the repeated measurements in separate records.

reshape2 succeeds the reshape package, and is succeeded by the package.

Repositories

Other resources

Related tags

1177 questions
-2
votes
1 answer

Undefined columns selected, how to solve?

When I try to run the following code I get an error: value <- as.matrix(wsu.wide[, c(4, 3, 2)]) Error in [.data.frame(wsu.wide, , c(4, 3, 2)) : undefined columns selected How do I get this line of work? It's part of dcasting my data. This is…
aleksa
  • 1
  • 2
-2
votes
1 answer

how to write a formula method that converts long to wide

In the twoway package, I have a twoway.default() method that takes a matrix or data frame and applies Tukey's methods for the analysis of twoway tables. Example: > data(taskRT) > taskRT topic1 topic2 topic3 topic4 Easy 2.43 3.12 …
user101089
  • 3,756
  • 1
  • 26
  • 53
-2
votes
1 answer

r reshape2 melt returns Warning in if (drop.margins) { : the condition has length > 1 and only the first element will be used

I have a piece of code that returns a warning message: Warning in if (drop.margins) { : the condition has length > 1 and only the first element will be used from deep inside the reshape2 melt function as shown in the error message. How do I…
-2
votes
1 answer

Reshaping data from long to wide format in R

I have a data set as shown below: Frame | X.axis | Y.axis | Z.axis -------|--------|--------|-------- 1 | 0.2 | 0.215 | 0.965 -------|--------|--------|-------- 2 | 0.54 | 1.25 | 2.219 -------|--------|--------|-------- 1 | …
-2
votes
2 answers

How to separate a column

The first column of my dataframe is a factor that contains two sets of information: the type of activation works (A1-4) and the month when it was carried out (about 50 observations in YYMM format). A simplified version could look like this: A =…
babesz
  • 43
  • 1
  • 9
-2
votes
1 answer

r Using dcast in for loop to find mean of multiple columns and compile them in a new dataframe

I have a dataframe (DF_melted) which I obtained by melting some other dataset. The DF_melted dataframe has columns "month","A","B","C","D","E","F". From the following code using dcast, I am able to get a dataframe which contains value of mean of the…
Sinha
  • 431
  • 1
  • 5
  • 12
-2
votes
1 answer

R Reshaping Data from long to wide by aggregating on a variable

I have row-wise transaction data in the following long format TransactionId ItemCode 101 123 101 521 102 423 103 871 103 982 103 131 I want to reshape this to get all items in one transaction in one row, so the new reshaped table looks…
SuhrudL
  • 21
  • 1
  • 5
-2
votes
1 answer

Generating tables for each factor level over a range of columns, in R with dplyr and reshape2

For a range of columns (variables) in a data frame, I need to generate tables for each level of each variable. I have created a function that finds the first column in the range (Q1a) and then runs a for loop for every column after. The loop finds…
Nick Holt
  • 116
  • 6
-2
votes
1 answer

Sequencing along two variables of interest in R

I am trying to create a sequence along two different parameters about how people have moved from one location to another. I have the following information name<- c("John", "John", "John", "Sam","Sam", "Robert", "Robert","Robert") location<-…
user3570187
  • 1,743
  • 3
  • 17
  • 34
-2
votes
1 answer

R Manipulate data frame with multiple information in columns

How can I reshape this dataframe regarding the multiple information of the columns 2:7 (day_rep), obtaining this new "datlong" dataframe with the coumns: "trat" "day" "rep" "value" dat <- read.table(header=T, text=' trat 5_1 5_2 6_1 6_2 7_1…
Juanchi
  • 1,147
  • 2
  • 18
  • 36
-2
votes
3 answers

Convert wide to long format in R

My data has a long format similar to the one below: ID Language MotherTongue SpokenatHome HomeLang 1 English English English 1 French French 1 Polish Polish 2 Lebanese …
Anthony
  • 67
  • 1
  • 6
-3
votes
1 answer

How to insert a name of list table into a column using R

I have data like this: # Data varx1 <- data.frame(datex = c("2018/01/01","2018/01/02","2018/01/03"), x = c(101,102,103)) varx2 <- data.frame(datex = c("2018/01/01","2018/01/02","2018/01/03","2018/01/04","2018/01/05"), x = c(10,11,12,13,14)) varx3…
Faryan
  • 409
  • 3
  • 11
-3
votes
1 answer

how can i restructure the data frame in R

I have the following df: >df cluster_no days_to_port channel 1 1 2.8 MMR 2 2 4.1 Spark Retail Stores 3 3 2.4 Spark Retail Stores 4 4 3.0 Spark…
Nishant
  • 1,063
  • 13
  • 40
-3
votes
1 answer

R code - restructure data, three columns of stacked data to rows

In this example data, three people sorted 10 items into a variable number of groups and provided a text label for each group. Person and label are text fields. Item var when downloaded and read into R is read as an integer. Item variable is…
-3
votes
1 answer

data cleaning and matching names in r

df1 <- structure(list(Name1 = structure(c(1L, 2L, 2L, 2L, 2L, 2L, 3L, 4L, 4L, 4L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 8L, 8L, 8L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 11L, 12L, 12L, 13L, 14L, 14L, 14L, 15L, 15L, 16L, 16L, 17L, 17L, 17L, 18L, 19L, 19L,…
William Liu
  • 339
  • 1
  • 2
  • 9
1 2 3
78
79