Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
17 views

Reshaping data from long to wide format using data within a column in R

I am attempting to change the format of my dataset from long to wide format in order to create a matrix. The data is currently structured as: year data.type plot species presence 2024 nc 35 Acer ...
Marshallia's user avatar
0 votes
0 answers
32 views

Issue loading r-caret library within conda environment for r

Issue I am trying to use the caret library but can't use the package due to a dependency issue regarding "reshape2". A simple library(caret) does not work. Traceback Error: package or ...
ajgallard's user avatar
0 votes
1 answer
51 views

reshape data.frame with duplicate values

I have data frame called sample_df as below: sample_df <- data.frame( date = c("2023-02-27", "2023-02-27", "2023-02-27", "2023-02-27", "2023-02-27&...
ugawangga's user avatar
0 votes
2 answers
64 views

Calculate variables within family in a long format dataset

I have a data set like this one: df <- data.frame(FAMID = c(1,1,2,2,3,4,5,5,6), IID = c("A","B","A","B","A","B","...
JuanJMV's user avatar
  • 145
0 votes
1 answer
39 views

Long format dataframe column hierarchy

I am working with long format dataframes and intend to write a package myself. While it is not crucial, I would like to adhere to common practice of column hierarchy, e.g. when I have 3 participants ...
FelixSchweigkofler's user avatar
0 votes
2 answers
49 views

How to combine two melt / gather / pivot_longer commands in R into one command?

I have a for my understanding rather simple problem, but I could not find a solution so far. I have a dataset with 4 columns that start with time (time1, time2...) and 4 columns that start with count (...
Feli's user avatar
  • 11
0 votes
1 answer
28 views

Melt dataset splitting columns by delimiter in r reshape2

I have a dataset of abundance of organisms across sites processed by 3 different people that I would like to take from wide to long format using column headers as information to split into different ...
user95146's user avatar
  • 310
1 vote
2 answers
66 views

Stacked barplot from 2 dataframes using 3 variables

I am looking to create a bar plot in R combining data from 2 different dataframes plus using a third variable as fill. The data: all_spp <- data.frame(NAME=c("A", "B", "C&...
Kristina's user avatar
  • 275
0 votes
2 answers
268 views

How to combine multiple columns to single columns (by header name)?

I currently have an Excel document that looks like this in a simplified way: A1 A2 B1 B2 B3 C1 C2 ... H12 1 5 11 14 15 19 22 ... ... 2 6 12 ...
Hotshot's user avatar
  • 159
1 vote
2 answers
85 views

How to combine columns of different excel files and renaming the column with the name of the initial file using R?

I have 96 different Excel files in a folder that all contain one single column, which looks approximately like this, whereby the uppermost line is the name of the Excel file: A1.xlsx Distance 245 534 ...
Hotshot's user avatar
  • 159
0 votes
1 answer
52 views

Wide to long format dataframe, where the wide dataframe has paired columns (AAA1 with value11, BBB1 with value22, CCC1 with value33 etc)

I am trying to convert a wide dataframe that contains the following columns: id, age, gender, AAA1, value11, AAA2, value12, ..., BBB1, value21, BBB2, value22, ..., CCC1, value31, CCC2, value32,... ...
Zach's user avatar
  • 1
1 vote
2 answers
53 views

In R, how to transpose row data to coulmn per variable? [duplicate]

I have some data like below dataA=data.frame(structure(list(Season = c(2021, 2021, 2021, 2021, 2021, 2022, 2022, 2022, 2022, 2022, 2023, 2023, 2023, 2023, 2023), ...
Jin.w.Kim's user avatar
  • 884
2 votes
3 answers
87 views

Convert the event-level dataset to the patient-level data in r

I need to convert the event-level dataset to the patient-level data i.e. convert a long dataset to a wider one based on deidnum as a key variable. Additionally, I want to create columns for each ...
Mohamed Rahouma's user avatar
0 votes
1 answer
17 views

I would like to reshape my data such that the individual items under the column ''variable'' become separate columns with their values under them [duplicate]

The current data looks like this: Please run the code below df1<- data.frame(Names= c(c(rep("Lincon",12), rep("Joe",12),rep("Megi",12))), Year= c(rep(...
Emmanuel's user avatar
0 votes
0 answers
206 views

Error in sum(X) : invalid 'type' (list) of argument

I am in need of help with this problem. I have been using this script for about 2 years with no issues. However, I recently had to format my PC and therefore reinstall R and RStudio. The code is the ...
Carolina V's user avatar
0 votes
1 answer
36 views

Reshaping data into long forma

I have two large data frames, the sample below shows what they look like: Name<-c("ST01","ST02","ST03") B1<-c(0.01,0.003,0.04) B2<-c(0.02,0.002,0.02) B3<-c(0....
Peter.2055's user avatar
1 vote
0 answers
106 views

"Aggregation requires fun.aggregate: length used as default" error when using cast() function from Reshape package

I am trying to use the cast() function from the Reshape package to convert a long format dataframe into wide format. Below is the dataframe (named textMessagesLong) I am working with. I am using the ...
OzkanGelincik's user avatar
0 votes
0 answers
111 views

Error when using unnest() following pivot_wider() in R

I have a dataset that I am trying to reshape as wider The original dataset is something like this #df Cell_line Gene AF COLO320 MYC 0.5 COLO320 KRAS 0.4 H524 ...
Jawad Alaa Edeen's user avatar
2 votes
2 answers
210 views

Reframing output of confidence intervals to combine mean, upper and lower values into one cell

I use the code below to calculate the mean, upper and lower confidence intervals of multiple variables at once. library(gmodels) library(purrr) dfci <- df %>% group_by(group) %>% dplyr::...
amir.fathi's user avatar
2 votes
2 answers
119 views

How to make four combination of points with the same ID in a data frame in R?

I am currently trying to make squares (polygons) from a data frame in R and in order to do that (according this guide), I need to have a data frame with 4 sets of paired points as their lon-lat ...
cinnamoroll's user avatar
0 votes
1 answer
50 views

I want to modify my dataset in R so that I can conduct a market basket analysis

I need to modify in R my dataset that looks like a classic table with observations in the row and variables in the column. Specifically, the first column reports a set of transactions identified by an ...
Aldo Verdino's user avatar
0 votes
1 answer
42 views

How to handle "variable" and "value" in melt reshape2 with Roxygen2

I'm trying a different method to boxplot two population means.I'm using reshape2's melt function which comes inbuilt with 2 columns, variable and value. Below is the code. It works but I get a warning ...
Jasmin Wilson's user avatar
1 vote
2 answers
73 views

dcasting long table along multiple columns

I am having a difficult time understanding dcast, and cannot get the right commands to get what I want. I will give a minimal repro. #generate the data ID <- c('a','a','a','b','b','b') Parameter &...
David Inman's user avatar
4 votes
1 answer
68 views

transform data frame from wide to long (several variables) using separator [duplicate]

I have a df like this one: FID <- c(1,2,3,4) d <- c(1,1,2,2) IID_1 <- c("1A","2A","NA","4A") IID_2 <- c("1B","2B","3B",...
JuanJMV's user avatar
  • 145
-1 votes
1 answer
70 views

Reshaping/Deduping long data to wide in R [duplicate]

I've been trying to reshape this long data into wide format by ID within excel with no luck. I tried using dcast but it did not give me the results I was expecting. I've attached a csv of how the data ...
willr's user avatar
  • 7
0 votes
1 answer
94 views

How to melt a dataframe with tidyverse, and create a new column

I have pet survey data from 6 households. The households are split into levels (a,b). I would like to melt the dataframe by aminal name (id.var), household (var.name), abundance (value.name), whilst ...
Paul's user avatar
  • 45
0 votes
2 answers
59 views

reshape function not mapping values correctly

I am working with a within-subjects design looking at how participants rated 20 videos across a variety of variables (valence, arousal, etc.) and am trying to turn my wide-format df into a long format ...
Sam Jones's user avatar
0 votes
1 answer
68 views

Got stuck while changing data format from wide to long

I am a complete beginner in R. I installed R couple of days ago to complete my course assignment. One of the instructions was that I have to change the data format from wide to long format. The data ...
Fardeen Kabir's user avatar
0 votes
3 answers
110 views

dcasting a dataframe using reshape2::dcast

I am trying to reshape a dataframe using dcast function of reshape2 package library(reshape2) dat = data.frame(aa = c('A', 'B', 'C', 'C', 'B')) dcast(dat, aa~aa) This generates below output aa A B ...
Brian Smith's user avatar
  • 1,347
1 vote
1 answer
52 views

transforming long data to wide in R

Hi i have data that looks like this : X snp_id is_severe encoding_1 encoding_2 encoding_0 chisq p.value AF_total AF_LATIN 1 1 chr21-10139833-A-C 0 0 1 ...
agnesa rivkin's user avatar
0 votes
2 answers
39 views

reshape data frame into colnames and rownames

My questions is self-explained by the example, but in short: I would to dcast the data frame and add 1 and NA depending on the matched that are in the original data frame. I tried reshape2::dcast(cars~...
user2300940's user avatar
  • 2,385
0 votes
0 answers
47 views

Running ANOVA test after melt function

I am trying to run an ANOVA test after using melt and the error keeps popping up. I do not know what I'm doing wrong Error in eval(predvars, data, env) : object 'W' not found rm(list=ls()) ...
Tanya Gleason's user avatar
0 votes
1 answer
29 views

How to stack values in one column by factor name in another column in R

I have a data frame with 4 columns, here is the structure: Abundance DayNight peak Family 1 2 Day Peak Pangasiidae 2 1 Night Non-Peak Cyprinidae 3 ...
Jackson A Swan's user avatar
1 vote
1 answer
31 views

What am I doing wrong in this dcast (reshape2) function?

So I have this table and I need to arrange it by team as rows and year (2010 - 2015) as attributes, so Ive tried with xtabs and table function, but I only get the count, instead of the points that ...
kaezar22's user avatar
1 vote
1 answer
41 views

Reshape binary data group by column and count

I want to reshape a data.frame to a matrix in the following format: Input: Typ1 Typ2 Maths Science English History 1 1 1 1 1 1 0 1 0 1 0 ...
Hölderlin's user avatar
0 votes
1 answer
71 views

Tidy up rbind(ddply()) R for transforming from wide to long

So I have figured out a solution on how I can transform my data from wide to long. The dataset had 190 columns representing 19 variables for 10 years (and additionally 31 columns that did not require ...
SarpsRosing's user avatar
1 vote
2 answers
99 views

remove missing values from dataframe and reshape the dataframe with the non-missing ones

I have a dataframe that has missing values at each column, but at different rows. For simplicity, let's see the following dataframe (real dataframe is much more complex): first_column <- c(1, 2, NA,...
ΚΩΝΣΤΑΝΤΙΝΟΣ ΠΑΝΑΓΙΩΤΟΥ's user avatar
1 vote
0 answers
78 views

r - How to reshape data from long to wide format (when you have messy data, many columns, and want to retain some of the original structure)

I have a dataset that I want to convert from long to wide format. I have checked the two most popular answers (here and here), but I can't make sense of them as they apply to my data structure. I want ...
aspark2020's user avatar
0 votes
1 answer
49 views

transforming complex wide data to long in R, multiple year columns, corresponding values, UTF-8 issues (Duplicate?)

What I have is a wide format, that need to get reshaped and sorted differently. I have 10 columns in total for year, one same year for all rows, different year per column. These I would like to merge ...
SarpsRosing's user avatar
0 votes
1 answer
210 views

Convert single row to a column in R

I have a data frame that has serveral columns along with sub-columns and it looks like this: I want to transform this data frame and make a new column from second row which can be considered as a sub ...
Vishal Sharma's user avatar
2 votes
1 answer
82 views

R Pivot Longer With Multiple Columns

HAVE = data.frame( COURSE =c( 1, 1, 1, 2, 2, 2, 3, 3, 3 ), STUDENT =c( 'A', 'B', 'C', 'A', 'B', 'C', 'A', 'B', 'C' ), FISH =c( 4, 8, 9, 1, 7, 1, 10, 10, 10 ), CAT =c( 9, 8, 10, 7,...
bvowe's user avatar
  • 3,344
2 votes
2 answers
56 views

Reshape the data from three columns to two column

I have a data like this : Response Prompt Prompt.Label Comments 1 Friend who si3 3_a 2 1 was si4_en 3_a 3 1 was si4_nag 3_a 4 ...
Ali Roghani's user avatar
3 votes
2 answers
92 views

Melt list of identical dataframes to one dataframe in R

I have a list waterlevels of nine identical dataframes containing information about piezometers K01 to K09. Each of these dataframes contains 96860 rows, all of them having 13 variables, except for ...
Lies's user avatar
  • 71
0 votes
0 answers
29 views

reshape2 melt a list of pixel image objects like in reshape

I have a list of pixel image objects from spatstat.geom (see example data below) and want to melt them into one data.frame. I do it with reshape::melt and it works fine. Now, I wanted to do it with ...
Saskia Schirmer's user avatar
8 votes
4 answers
802 views

Is there an alternative to reshape2::melt for multidimensional arrays in base R or tidyverse?

Suppose I have a 3-dimensional array g with dimensions [x,y,z]. reshape2::melt(g) would produce a data frame with columns giving indices of x,y,z and value where value contains the values in each ...
DanO's user avatar
  • 650
0 votes
1 answer
41 views

Wide to long omitting the early NAs

I have this simple data frame, colx <- c(2002-01, 2002-02, 2002-03, 2002-04) cola <- c(10, 20, NA, 40) colb <- c(NA, NA, NA, 400) colc <- c(1000, 2000, 3000, 4000) df <- data.frame(...
JontroPothon's user avatar
0 votes
2 answers
96 views

Convert data.frame from long to wide with rank in R

I have a data.frame as follows: d1 = data.frame( g = factor(rep(1:3, rep(4,3))), x = c(21,24,27,20,20,18,19,15,22,25,27,22) ) d2 = data.frame(d1, r=rank(d1$x)) #add ranks of x-elements d2 # g ...
John Stone's user avatar
0 votes
2 answers
54 views

Split string based on a key word in r programming, keyword= BAS, Getting duplicate results. especially FRM_id = 1014

if (!require("librarian"))install.packages("librarian") librarian::shelf(stringr,stringi,dplyr,reshape2) FRM_ID<-c(1006,1007,1011,1012,1014,1014,1015) FRM_Name<-c("...
BobbyG's user avatar
  • 45
0 votes
0 answers
281 views

converting a df from wide to long but warning message: number of items to replace is not a multiple of replacement length

I would like to turn this dataframe from wide to long. I know that there are some similar posts about the topic, for instance I have tried all the options from this one: Reshaping wide to long with ...
Charlotte Juton 's user avatar
0 votes
0 answers
47 views

Reshape the bike share recorded data into bike share counts

Everyone I am struggling to reshape the bike share recorded data. data link : https://www.kaggle.com/code/samratp/bike-share-analysis/data?select=NYC-2016-Summary.csv The original data form is ...
wang's user avatar
  • 1

1
2 3 4 5
24