Questions tagged [long-format-data]
56 questions
3
votes
1 answer
Reshaping a dataframe from wide to long format in R using multiple sets of variables
I have a dataset in wide format with participants' information for multiple waves of a survey, including their country, gender, age at interview, and the year and whether they participated in each wave of a survey.
Here is a sample of the…

saif
- 31
- 1
2
votes
1 answer
transform data from wide to long in r
I have a dataset similar to this:
id_male<-rep(c(1:100),times=1)
df1<-data.frame(id_male)
df1$id_female <- sample(500:1000, length(df1$id_male), replace=TRUE)
df1$var_ma_1 <- sample(500:1000, length(df1$id_male))
df1$var_ma_2 <- sample(500:1000,…

llxx2021
- 83
- 4
1
vote
3 answers
Transform table to wide format where not all columns are in long
I'm trying to transform a complex dataframe such as (:
olddata_long =
A B C SAMPLE_ID 1 2 3 4 5
X1 Y1 Z1 SAMPLE1 G1 H1 J1 K1 L1
X1 Y1 Z1 SAMPLE2 G2 H2 J2 K2 L2
X2 Y2 Z2 SAMPLE1 G3 H3 J3 K3 L3
X2 Y2 Z2 SAMPLE2 …

Gabriel G.
- 555
- 1
- 3
- 13
1
vote
1 answer
How do I improve this syntax for creating a subset with factors?
EDIT: A moderator has flagged this this question as very similar to mine. As a neophyte, I do not see these as similar. This reflects the discrepancy between my understanding of R and the moderator's. They see the obvious connection because they are…

Jeff Boggs
- 45
- 6
1
vote
2 answers
Complicated pandas dataframe melt
I have an excel worksheet that has some data in the following format:
Unnamed: 0 Unnamed: 1 Unnamed: 2 Unnamed: 3 Unnamed: 4 Unnamed: 5 Unnamed: 6 Unnamed: 7 Unnamed: 8 Unnamed: 9 Unnamed: 10 Unnamed: 11 Unnamed: 12
0 Hour 1 FI NO2…

Tom
- 109
- 9
1
vote
1 answer
Split long format data frame by character indicator
I have data in long format, where data frames are essentially stacked on top of each other.
I want to seperate them before changing to wide format. I need some way of telling R to recognize "Sell curve" and "Buy curve" as indicators that seperate…

KjetilH
- 47
- 4
1
vote
1 answer
R: How to transform long longitudinal data to wide longitudinal data, when I only have the age (in days) as an indicator of measurement time?
I have a long-formatted set of longitudinal data with two variables that change over time (cognitive_score and motor_score), subject id (labeled subjid) and age of each subject in days at the moment of measurement(labeled agedays). Measurements were…

Makie
- 37
- 4
1
vote
1 answer
Create variable counting unique IDs in long format table
I would like to structure my long format SPSS file so I can clean it and get a better overview. However, I run into some problems.
Patients appear several times in the database (Column patientID). How can I make a new variable that contains only 1…

Anne
- 11
- 2
1
vote
1 answer
R - Creating a new variable based on multiple observations
My dataset represents patients which have been treated multiple times. The dataset is in a long format, patients either get treatment A, C or S or a combination. A and C are never combined.
Simply put, the data looks something like this:
df <-…

Anneke
- 53
- 7
1
vote
4 answers
Is there a pandas function to unpack a column that's a dict into a long format?
So the data has the column [outbreakMap] as a pandas series. I recreated a snippet of the data as a df below:
Initial Data:
data = {0: {'id': '53545',
'latitude': -1.5168500000000003,
'longitude': 105.2985,
'outbreakMap': {'ob_102795':…

Anonymous
- 453
- 1
- 6
- 14
1
vote
2 answers
Fetching values from one column based on other column keys in long-formatted dataset
I have a long format dataset of 100,000+ individuals, capturing clinic visits at 5 different time points (not chronological). I've included an example dataset below that replicates the formatting of my data:
ID: participant ID visit_number: order…

ceruleanclouds
- 37
- 4
1
vote
1 answer
What is the stubname for fields with multiple separators?
I'm trying to use pd.wide_to_long and I'm a little bit stumped on using the stubnames parameter:
https://pandas.pydata.org/docs/reference/api/pandas.wide_to_long.html
Here are the field names:
Expected behavior: the transformation of a wide format…

Anonymous
- 453
- 1
- 6
- 14
1
vote
3 answers
How do I make sscanf ignore white spaces? C
I'm trying to read formatted data with sscanf in this format:
"%d,%d,%d"
for example,
sscanf(buffer, "%d,%d,%d", n1, n2, n3)
and it is critic that there is no white space between every number, because the input comes like this, for…

PythonAddict
- 57
- 5
1
vote
1 answer
Slicing long form R data into multiple columns
I've been given some data that I've combined into long form, but I need to get it into a certain format for a deliverable. I've tinkered with dataframe and list options and cannot seem to find a way to get the data I have into the output form I…

Shawn Janzen
- 369
- 3
- 15
1
vote
1 answer
How to transform hierarchical data (from Beyond 20/20) from a partially wide format to long format in R?
I have some census data which is partially in long and partially in wide format that was exported from Beyond 20/20. I am struggling with how to reformat the data, since it is not totally in wide format as is. In the following data set, there is the…

ksweet
- 93
- 5