Questions tagged [reshape2]
The reshape2 package in R contains functions that allow data to be transformed into more convenient forms.
1,140
questions
0
votes
1
answer
14
views
R package Error: package or namespace load failed for ‘reshape2’ in loadNamespace: there is no package called ‘magrittr’
I have installed install.packages("reshape2") on R 3.4.3
but when I try to use that library like
library(reshape2)
I get the below error
Error: package or namespace load failed for ‘...
0
votes
3
answers
28
views
R -- transform tab delimited string to long format
How to you reshape a string delimited by a tab or space into a long format? The string (called label here) can be of different lengths.
I have this
var label
1 work 100 101
2 sleep 500 ...
1
vote
2
answers
47
views
Referring to the row above when using mutate() in R
I want to create a new variable in a dataframe that refers to the value of the same new variable in the row above. Here's an example of what I want to do:
A horse is in a field divided into four zones....
0
votes
0
answers
8
views
Reshape to wide format with a time column [duplicate]
This I am certain is a duplicate question. Pardon me for this violation. I have a dataset like this in a long format.
ID TIME Col1 Value
A 1 X1 25
B 1 X1 26
C 1 ...
0
votes
1
answer
20
views
R split by group and create new columns
I'm trying to split a data frame from long to wide format by converting selected rows to columns. Here is the current general long-format structure:
data_long <- data.frame(
id = c("kelp&...
1
vote
2
answers
21
views
Pivot data frame without Null
I have looked to all similar question of stackoverflow but without success.
Consider the iris data set. I just want to put the species as columns, and get below each species names, only the Sepal ...
1
vote
1
answer
50
views
r arrange data nested wide format
I have a dataset like this
Time1 Time2 Time3
A
Median 0.046 0.12 0
Q1, Q3 -0.12, 0.22 -1.67, -4.59 -0.245,...
2
votes
1
answer
32
views
Stack bars with percentages and values shown
Here is my dataframe - data_long1
data.frame(
value = c(88, 22, 100, 12, 55, 17, 10, 2, 2),
Subtype = as.factor(c("lung","prostate",
"...
0
votes
2
answers
28
views
why sklearn LinearRegression model does not accept one dimensional data?
I'm trying to learn the basics of Linear Regression.
I tried to build the simplest model with the simplest data for the starter .
for data I had:
## Data (Apple stock prices)
apple = np.array([155, ...
2
votes
2
answers
57
views
reshape from wide to long, simple data.table issue
I know there must be a one-line data.table solution for this, probably with dcast, but I can't figure it out.
I have data like this:
library(data.table)
data1 <- data.table(
id = seq(1:5),
code ...
0
votes
1
answer
72
views
Plotting column graph with multiple groups using ggplot
I have dataset below and would like to have the results in the picture attached using ggplot.
bar_df
class boys girls
a 20 30
b 40 30
c 50 50
...
0
votes
3
answers
65
views
How to do a nested 2 level reshape in R?
I am currently working on a survey project that asks about respondents' economic activities. So we will ask the jobs/businesses they have, and since some jobs/businesses are seasonal, we ask about ...
0
votes
0
answers
14
views
how to arrange a table by putting a column variable in several row? [duplicate]
I am trying to arrange a table with two columns :
V1 V2
1 F3_Ct10_1.sub Ct10
2 F3_Ct10_2.sub Ct10
3 F3_Ct10_3.sub Ct10
4 F3_Ct11_1.sub Ct11
5 ...
1
vote
1
answer
24
views
Expand dataset by count column in Dplyr
I have a dataset as follows:
library(tidyverse)
df <- data.frame(
report_date = c("2020-03-14", "2020-03-14", "2020-03-19", "2020-03-20"),
...
0
votes
2
answers
27
views
Changing dataframes in bulk? How to apply a list of operations to multiple dataframes?
So, I have 6 data frames, all look like this (with different values):
Now I want to create a new column in all the data frames for the country. Then I want to convert it into a long df. This is how I ...
2
votes
1
answer
40
views
Spread a dataframe and relabel column names
Probably a tidyr or a reshape2 question.
I have this type of a data.frame:
df <- data.frame(group = c("A","B","C","D"),
id1 = c("AV14D&...
5
votes
3
answers
97
views
Pivoting to a longer format using pivot_longer
I'm trying to pivot to a longer format using dplyr::pivot_longer, but can't seem to get it to do what I want. I can manage with reshape::melt, but I'd also like to be able to achieve the same using ...
1
vote
2
answers
30
views
Converting rows into columns based on the values in the rows, in R
This is the table I am working with. I want to convert reservation into separate columns.
I want it to be transformed into something like this. I have been trying to do this using reshape2 and dplyr'...
1
vote
0
answers
38
views
Reshaping multiple columns with disordered values
I have a dataset with multiple columns that I want to reshape. Essentially, the data from the columns corresponding to the numerals become columns taking their corrsponding value in that row from the ...
0
votes
0
answers
13
views
Is there a way to use the dcast function in the reshape tool
sc<- c(1,3,1,4,5,3)
al <- c("a","b","c","d","e","f")
df <-data.frame (sc,al)
What I want is
a table that looks like this
sc |...
0
votes
1
answer
116
views
Convert columns into rows, R data.frame [duplicate]
I want to repeat heach column into a new row as the next example:
Date<- c(seq(as.Date("2000/1/1"), by = "month", length.out = 3))
A<- c(seq(2,4,length.out=3))
B<- c(seq(...
0
votes
1
answer
76
views
Data manipulation using dcast R
I have a data as shown below:
Data
Flag
Answer
X
1
Yes
X
2
Yes
Y
1
Yes
Y
2
No
Z
1
Yes
Z
2
Yes
and I want to convert it to:
Data
1
2
X
Yes
Yes
Y
Yes
No
Z
Yes
Yes
I know I have to use dcast ...
-2
votes
1
answer
44
views
How best to use R to reshape dataframe from long to wide and combine values
I have a dataframe of about 2000 rows and 3 columns. In essence, I want to reshape this dataframe to be wider than longer. This is an example of my current data:
ID
Procedure
Date
D55
Sedation
01/01/...
2
votes
6
answers
92
views
Split a string by two delimiters only in the first occurrence
I have read many examples here and other forums, tried things myself, but still can´t do what I want:
I have a string like this:
myString <- c("ENSG00000185561.10|TLCD2", "...
3
votes
2
answers
48
views
How to recode values in a column if the value equals the column name, across an entire dataset in R
I have a very large dataset that I'm trying to wrangle. Here's a few of the first few rows of the variables I'm interested in for the purposes of this question:
id
stressor
1
Homelessness
1
...
0
votes
1
answer
55
views
Spread or dcast and fill in counts [duplicate]
Probably a basic question.
I have a key - value data.frame(df below):
features <- paste0("f",1:5)
set.seed(1)
ids <- paste0("id",1:10)
df <- do.call(rbind,lapply(ids,...
2
votes
1
answer
54
views
R- How to reshape Long to Wide with multiple variables/columns
I started off with the following subset of my data
UserID labelnospaces responses
1 Were you given any info? yes
1 By using this service..? yes
1 How satisfied are you? ...
1
vote
2
answers
113
views
Why is the Facet_Grid Output Different from Its Data
I have these time series data which I plotted as follows
## simulate ARIMA(1, 0, 0)
set.seed(289805)
x1 <- arima.sim(n = 10, model = list(ar = 0.8, order = c(1, 0, 0)), sd = 1)
set.seed(671086)
x2 &...
1
vote
1
answer
37
views
Can I use a different method/function for grouped dataframe?
I have been following a tutorial where a guy was trying to pull data from wbstats into a dataframe (gross domestic product data).
I think there is something wrong with the last code segment, as I have ...
0
votes
0
answers
36
views
getting error when making Function: Error in value.var %in% names(data) : object 'x' not found
There is something wrong in my function getting error:
Here is the code:
fun <- function(x){
reshape2::dcast(x, formula = PROVINCE + DISTRICT ~ DAILY_LANG,
value.var ...
0
votes
1
answer
21
views
How to turn data from long to wide format so that duplicate rows get added to the end to make new columns in R?
I got the following data.
ID NAME STATUS OKR_T OKR_N NR
1 Jack 1 34 OK1 0
1 Jack 1 433 OK2 0
1 Jack 1 12 OK3 1
2 Bill 2 34 ...
2
votes
1
answer
48
views
Looping to get outliers data using dplyr in R
I have task to find outliers data, here it is my data:
# combination 1
datex <- c(rep("07/01/2021", 24), rep("07/02/2021", 24), rep("07/03/2021", 24), rep("07/04/...
1
vote
1
answer
56
views
Index - Match using dplyr in R
Here it is mydata:
datex <- c(rep("2021-07-01", 9), rep("2021-07-02", 9))
hourx <- rep(rep(0:2),6)
seller <- c("Se1","Se1","Se1","Se2&...
1
vote
2
answers
47
views
Turn specific row values into columns using R
I have a dataset similar to the one listed below
v1 <-c('name1','0/0','0/1','1/1','name2','0/0','1/1','name3','0/0','0/1','1/1','name4','0/0','0/1','1/1','name5','0/0','1/1')
v2 <- c(NA,95,3,2,...
0
votes
1
answer
51
views
Looping to get all combination using dplyr in R
Here it is my data
## Data
datex <- c(rep("2021-01-18", 61), rep("2021-01-19", 125))
hourx <- c(0,1,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,16,10,0,1,1,...
0
votes
0
answers
55
views
While running melt function from reshape2 package, the code is getting stuck in log
install.packages('reshape2')
library(reshape2)
frm.long1 <- melt(frm.1, id.vars = c("name", "gender"), measure.vars = c(3,4,5,6,7),
variable.name = "...
0
votes
1
answer
61
views
Reshape large dataset from wide to long with two ID variables
I want to change my data from long to wide format using two ID variables.
I have the below code that works with the below example dataset. However, when I run this code with a much larger dataset that ...
0
votes
0
answers
129
views
ANSWERED: R Base Error - Arguments imply differing number of rows
I am getting this error message when trying to plot a 1000x4 table using gg_vistime.
(Translated from german: Arguments imply differing number of rows: 0, 1000)
What exactly does this mean?
I have ...
0
votes
2
answers
59
views
Reshaping large data set
I am trying to reformat my data set. Currently, this is what it looks like:
SeqId
PlateId
Target
TargetFullName
1
11
111
111
2
22.
222.
2222.
However, I'd like it to look like this:
-----
SeqId
...
1
vote
2
answers
38
views
Reshaping multiple long columns into wide column format in R
My sample dataset has multiple columns that I want to convert into wide format. I have tried using the dcast function, but I get error. Below is my sample dataset:
df2 = data.frame(emp_id = c(rep(1,2),...
0
votes
1
answer
16
views
Pivoting/combining a table in R to get rows based on key ID column (tidyverse?) [duplicate]
I have a table (Table 1) that has matched pairs as rows, like this:
ID
Neighbour
Cell_A
Cell_B
Cell_A
Cell_C
Cell_D
Cell_C
Cell_D
Cell_E
and what I want is a table like this:
ID
Neighbour
...
0
votes
2
answers
60
views
Reshape data table using multiple timevar
I have a dataset DT where each row represents the performance of an individual in a race:
personID
raceDate
raceID
finPos
person1
2009-08-14
489801
2
person1
2010-04-17
502397
6
person1
2011-03-10
...
1
vote
2
answers
46
views
Un-melting a dataframe in generalised way
Let say I have below data.frame
library(reshape2)
set.seed(1)
dat = data.frame(X1 = sample(letters, 10, replace = T), X2 = sample(letters, 10, replace = T), X3 = sample(LETTERS, 10, replace = T), X4 ...
2
votes
3
answers
74
views
Adding rows of two categorical variables in a long dataset?
I have a matrix in a long format (panel data) with several string variables, a categorical variable and a variable with numerical values.
The data contains information on output for several industrial ...
0
votes
0
answers
16
views
Aggregate dataframe using sum [duplicate]
Basically I have a data frame with 1000 00 rows and although I’m sure what I’m trying to achieve is quite strait forward I can’t get my head around it or I might just not describing what I need to ...
0
votes
1
answer
191
views
calculate summary statistics with repeated measures / long data in R
Apologies if this has been asked elsewhere / if I am using the wrong terms, I have been trying to search for the correct way to do this but with no success so far.
I have an experimental design with 3 ...
0
votes
0
answers
38
views
percentage stacked barcharts on the x axis
I have a dataset with a few factor coslumns, i am able to make a stacked percentage bar chart for each of them like below tutorial from GitHub, but i dont want to create 3 plots or use facet fucntion, ...
0
votes
1
answer
36
views
How to convert a data frame from wide to long with multiple columns [duplicate]
I have a data frame like this that was produced using the 'reshape' function. I was wondering whether there was an 'opposite' to the reshape function that allows me to turn a data frame from wide to ...
1
vote
3
answers
72
views
Getting Rolled Up Data into Tidy Format
I have rolled up data that I am trying to get in a "tidy" format. Here is a sample of the data. Level 1 = the sum of all Level 2 or 3 items within the same Group.
Lights (2) are a ...
1
vote
3
answers
140
views
Split Column, convert resulting columns to factors
My goal is to split a charcter column consisting of 1's and 0's into their own columns. I want the new columns to be of type "factor". I have found a nice way to split the column (using ...