Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
1 vote
1 answer
24 views

Long to wide format based on variable suffixes in tidyverse in R

I wonder if there is a way for my DATA to be reformatted to my Desired_output below? Specifically, for each unique study, we stick together a pair of pre and postNUMBER together, separately for T and ...
Simon Harmel's user avatar
  • 1,449
1 vote
2 answers
42 views

How to get column-wise summary statistics with missing codes?

I have written a custom function ord_table() to extract summary statistics from a series of databases. To get those summary statistics, I have to filter out missing data codes (all codes are large ...
Suzanne Segerstrom's user avatar
1 vote
1 answer
25 views

Function not capturing change in values

I have the following dataframe: state_territory_code week_nbr CA WEEK 49 CA WEEK 49 FL WEEK 49 CA WEEK 50 TN ...
mexicanRmy's user avatar
2 votes
2 answers
30 views

Wide format data by pasting two sets of variables into one in R

I've tried to wide-format my DATA into my Desired_output using: pivot_wider(DATA, names_from = Year, values_from = c(Type, Language)) without success. Is there a way to achieve my Desired_output? ...
Simon Harmel's user avatar
  • 1,449
1 vote
1 answer
69 views

Get minimum through record iterations in pandas dataframe

I have created the following pandas dataframe: import pandas as pd import numpy as np ds = { 'trend' : [1,1,1,1,2,2,3,3,3,3,3,3,4,4,4,4,4], 'price' : [23,43,56,21,43,55,54,32,9,12,11,12,23,3,2,1,1]} ...
Giampaolo Levorato's user avatar
0 votes
2 answers
54 views

Return the name of a column which matches a date value

I have a data.frame with about 66k rows and 150 columns. For the purposes of this question, this is a sample. All columns are date objects. structure(list(fixed_date = structure(c(19267, 19239, 19120, ...
Alejandro Carrera's user avatar
2 votes
4 answers
50 views

Tabulate a column in data.frame ignoring the order of elements in it in R

In my DATA below, I wonder how to table() the variable lang_comb ignoring the order? For example, "english spanish french" and "french english spanish" are to be considered ...
Simon Harmel's user avatar
  • 1,449
1 vote
3 answers
46 views

Finding rows in a data.frame that are the same on one variable but different on another variable in R

In my DATA below, how could I filter the rows where the Nm values are the same but Descr values are different to achieve my Desired_out below? DATA <- read.table(header=T, text =" Cd Nm ...
Simon Harmel's user avatar
  • 1,449
2 votes
1 answer
64 views

I want to divide different index

On below dataframe, I want to divide "Inventory" value by "OUT" value with +1 index and output to DOH columns. For example, my expected output DOH columns on index 1 are the "...
Sattai's user avatar
  • 15
0 votes
1 answer
36 views

Using Value from Another Function in Pandas .Applymap()

Is it possible to color code DataFrame cell values based on its value compared to the value returned from another function. Here is an example of the DataFrame coloring that I created using the ...
Rwt987265's user avatar
3 votes
3 answers
51 views

How to filter out numbers with n digits in a dataframe in R?

In my DATA below, I'm trying to subset()/dplyr::filter() the INs that are 5 digits long. I'm using the following without success. Is there a better solution? Tried: subset(DATA, nchar(sub('\\.[0-9]+', ...
Simon Harmel's user avatar
  • 1,449
1 vote
1 answer
25 views

How to merge two columns when long-formatting data frame in R

Below, I'm can use tidyr::pivot_longer(DATA, -InstNm, names_sep = "_", names_to = c("Indicator", ".value")) to get very close to my Desired_output. But I wonder how I can ...
Simon Harmel's user avatar
  • 1,449
0 votes
1 answer
26 views

Long-formatting several sets of similarly named of variables in an R data.frame

I have several sets of columns whose names are related. For example, in the toy DATA below, one set of variables start with OTE_ and another set of variables start with RAE_. In my actual data, I have ...
Simon Harmel's user avatar
  • 1,449
0 votes
1 answer
32 views

Illegal start of simple expression when calling scala function

I have a function declared outside the main method to melt a wide data frame that i got from this post How to unpivot Spark DataFrame without hardcoding column names in Scala? def melt(preserves: Seq[...
P201_eng's user avatar
0 votes
0 answers
16 views

keeping key as a column after groupby [duplicate]

i want the groupby key to be a column, but instead it is returned as one space below the others. def function(list, A, B, C) A_dict = pd.DataFrame(list(zip(list, A)), columns = ['site', 'A'...
Daisy's user avatar
  • 29

15 30 50 per page
1
2 3 4 5
124