# Numpy turn hierarchy of matrices into concatenation

Advertisements I have the following 4 matrices: >>> a array([[0., 0.], [0., 0.]]) >>> b array([[1., 1.], [1., 1.]]) >>> c array([[2., 2.], [2., 2.]]) >>> d array([[3., 3.], [3., 3.]]) I’m creating another matrix that will contain them: >>> e = np.array([[a,b], [c,d]]) >>> e.shape (2, 2, 2, 2) I want to "cancel the… Read More Numpy turn hierarchy of matrices into concatenation

# How do I rearrange this data frame in R?

Advertisements I am sure this has been answered, but I am having difficulty having things make sense in my specific use-case. I have this table: > data.frame(ID = c(1, 2, 3, 4, 5, 6, 7, 8, 9), > Class1 = c("AB", "AB", "BC", "BC", "BC", "CD", "CD", "AB", "BC"), > Value1 = c(80, 90, 50,… Read More How do I rearrange this data frame in R?

# Reshaping data frame with old variables to be new rownames tidyverse

Advertisements how are you? I am struggling trying to reshape a data frame in R. Im working on a Shiny App and i need to reshape my data on a way that in the columns i have the values for two different years, so i can calculate the variation. The main idea is that the… Read More Reshaping data frame with old variables to be new rownames tidyverse

# R: How can I reshape my data.frame from wide to long using a Date variable?

Advertisements Edit: This question was closed, but it is different than its predecessors as it concerns a time series and the answer provided is so convenient that I believe it will help many beginners who don’t know how to use the arguments correctly for a time series. How can I reshape my data frame so… Read More R: How can I reshape my data.frame from wide to long using a Date variable?

# How to find the mean and reshape an array in python

Advertisements I have an array of the shape (901, 201, 3, 20). Please, how can I find the mean of the third matrix to give me (901, 201, 20) or (901, 201, 1, 20)? >Solution : Assuming you are using numpy, this is quite easy using numpy.mean. The first argument would be the array, and… Read More How to find the mean and reshape an array in python

# Aggregation and Restructuring two table in R

Advertisements I have two tables like that; Test Comp.Name A Test Comp.1 B Test Comp.1 B Test Comp.2 C Test Comp.2 A Test Comp.3 B Test Comp.4 table1 <- data.frame("Test" = c("A Test", "B Test", "B Test", "C Test", "A Test", "B Test"), "Comp Name" = c("Comp.1", "Comp.1", "Comp.2", "Comp.2", "Comp.3", "Comp.4")) Test.Name Comp.1 Comp.2… Read More Aggregation and Restructuring two table in R

# How can I melt a dataframe from wide to long twice on the same column?

Advertisements I have a dataframe: data = [ [1, "2022-04-29", 123, "circle", 1, 3, 6, 7.3], [1, "2022-02-10", 456, "square", 4, np.nan, 3, 9], ] df = pd.DataFrame( data, columns=[ "ID", "date", "code", "shape", "circle_X_rating", "circle_Y_rating", "square_X_rating", "square_Y_rating", ], ) df ID date code shape circle_X_rating circle_Y_rating square_X_rating square_Y_rating 1 2022-04-29 123 circle 1 3.0… Read More How can I melt a dataframe from wide to long twice on the same column?

# Reshape strings within a dataframe in R

Advertisements I have a dataframe that looks like this data.frame(service=c("1,2,3,4","2,4,5","1,3,4"), score=c("1,2,1,3","1,1,3","1,1,1")) a b 1 1,2,3,4 1,2,1,3 2 2,4,5 1,1,3 3 1,3,4 1,1,1 The variable service refers to a categorical variable from 1-5, while the score, is also a categorical variable from 1-3 for each of the previous service. Note that each respondent have taken different… Read More Reshape strings within a dataframe in R

# Can not reshape 2 dimensional array to 3 dimensional array for RNN in python

Advertisements I can not reshape the array into 3-dimensional one. Here is the example dataset: import pandas as pd import numpy as np df = { "a": [0.06 , 0.07, 0.45, 0.98, 0.97 ], "b": [12,45,65, 56, 34], "c": [2,5,5, 5, 3], "d": [23,55,25, 15, 34], "e": [0.0005,0.55555,0.383825, 0.4747477415, 0.348344334], "f": [0.0236 , 0.3407, 0.4545,… Read More Can not reshape 2 dimensional array to 3 dimensional array for RNN in python

# Merge wide and long dataset into wide dataset in R (by combining certain column headers and certain cells into new column headers)

Advertisements I’ve 2 datasets Participant performance: 1 participant/row Participant ratings: >1 participants/row (1 rater/row) I need to merge the 2 datasets into 1 dataset with 1 participant/row (including NAs). I’ve included reproducible toy examples of the 2 datasets I have as well as a reproducible toy example of the merged dataset that I need below.… Read More Merge wide and long dataset into wide dataset in R (by combining certain column headers and certain cells into new column headers)