grouping

Combine multiple plots, generated using the “by” R function, in one figure

∥☆過路亽.° 提交于 2021-02-02 09:40:32
问题 I have a data frame containing multiple numeric columns and one column with different factors. I'd like to produce a unique image containing the plots of the numeric columns, by factor. I tried the following: varA <- runif(40) varB <- runif(40) varB <- runif(40) varC <- runif(40) mainVar <- c(rep('cat', 10), rep('dof', 10), rep('mouse', 10), rep('frog', 10)) plotData <- data.frame(varA, varB, varC, mainVar) pdf('asd.pdf') par(mfrow=c(2,2)) by(plotData, plotData$mainVar, function(x){ par(mfrow

Combine multiple plots, generated using the “by” R function, in one figure

可紊 提交于 2021-02-02 09:40:07
问题 I have a data frame containing multiple numeric columns and one column with different factors. I'd like to produce a unique image containing the plots of the numeric columns, by factor. I tried the following: varA <- runif(40) varB <- runif(40) varB <- runif(40) varC <- runif(40) mainVar <- c(rep('cat', 10), rep('dof', 10), rep('mouse', 10), rep('frog', 10)) plotData <- data.frame(varA, varB, varC, mainVar) pdf('asd.pdf') par(mfrow=c(2,2)) by(plotData, plotData$mainVar, function(x){ par(mfrow

Combine multiple plots, generated using the “by” R function, in one figure

蹲街弑〆低调 提交于 2021-02-02 09:39:11
问题 I have a data frame containing multiple numeric columns and one column with different factors. I'd like to produce a unique image containing the plots of the numeric columns, by factor. I tried the following: varA <- runif(40) varB <- runif(40) varB <- runif(40) varC <- runif(40) mainVar <- c(rep('cat', 10), rep('dof', 10), rep('mouse', 10), rep('frog', 10)) plotData <- data.frame(varA, varB, varC, mainVar) pdf('asd.pdf') par(mfrow=c(2,2)) by(plotData, plotData$mainVar, function(x){ par(mfrow

How to group objects from a list which can belong to two or more groups?

拥有回忆 提交于 2021-02-01 03:59:08
问题 I have a list of Items where each Item can belong to one or more category. For a limited set of categories(string) I want to create a map with category as key and list of Items as value. Assume my Item class is defined as shown below: public static class Item{ long id; List<String> belongsToCategories; public List<String> getBelongsToCategories() { return belongsToCategories; } public void setBelongsToCategories(List<String> belongsToCategories) { this.belongsToCategories =

Grouped boxplot in R

主宰稳场 提交于 2021-01-29 20:56:36
问题 df <- data.frame(values = c(2.5,12,4.8,56,78),samples = c('45fe.K2','59ji.K2','59rc.K1','45hi.K1','96hu.K1'),group = c('K2','K2','K1','K1','K1')) df values samples group 1 2.5 45fe.K2 K2 2 12.0 59ji.K2 K2 3 4.8 59rc.K1 K1 4 56.0 45hi.K1 K1 5 78.0 96hu.K1 K1 I want to generate a group grouped boxplot. So I want one plot with a K1 and K2 boxplot. I thought this https://www.r-graph-gallery.com/265-grouped-boxplot-with-ggplot2.html would do it but I can´t figure out how p1 <- ggplot(df, aes(x

Grouped boxplot in R

▼魔方 西西 提交于 2021-01-29 18:38:00
问题 df <- data.frame(values = c(2.5,12,4.8,56,78),samples = c('45fe.K2','59ji.K2','59rc.K1','45hi.K1','96hu.K1'),group = c('K2','K2','K1','K1','K1')) df values samples group 1 2.5 45fe.K2 K2 2 12.0 59ji.K2 K2 3 4.8 59rc.K1 K1 4 56.0 45hi.K1 K1 5 78.0 96hu.K1 K1 I want to generate a group grouped boxplot. So I want one plot with a K1 and K2 boxplot. I thought this https://www.r-graph-gallery.com/265-grouped-boxplot-with-ggplot2.html would do it but I can´t figure out how p1 <- ggplot(df, aes(x

Grouping people in pandas dataframe with customized function

最后都变了- 提交于 2021-01-29 15:57:15
问题 Introduction: I have a pandas dataframe with people who live in different locations (latitude, longitude, floor number). I want to cluster 3 people each in one group. This means, at the end of this process, every person is assigned to one particular group. My dataframe has the length of multiples of 9 (e.g 18 people). The tricky part is, people in the same group are not allowed to have same location in terms of latitude and longitude. What is going wrong? After I apply my function to the

SQL first date for the first occurrence of a value

我与影子孤独终老i 提交于 2021-01-29 08:28:19
问题 I have a table with clients and the history of their rating (low, medium, high) which gets assessed quarterly. Example table: client_ID rating eff_from 111 high 30.09.2018 111 high 30.06.2018 111 medium 31.03.2018 111 high 31.12.2017 111 high 30.09.2017 111 low 30.06.2017 222 medium 30.09.2018 222 high 30.06.2018 222 high 31.03.2018 222 low 31.12.2017 222 low 30.09.2017 222 medium 30.06.2017 I would like to get the minimum eff_from date for the latest rating. From the table above, that would

Aggregate results by date intervals in R

依然范特西╮ 提交于 2021-01-29 08:27:58
问题 I'm using R and I have my data on data.tables objects. My data is of the format ID, Date1, Date2, Row For each ID I can have more than one entry, and the two dates define a time interval. I want to be able to aggregate all the entries by id and overlapping time intervals. I do know how to do it with for loops and such, but I wonder if there is a better way. Example: data = data.table( id = c(1,1,1,2,2,3,3), Row = c(1,2,3,4,5,6,7), Date1 = c("2018-01-01", "2018-01-05", "2018-01-21", "2018-01

How to restructure an array of single-element associative arrays into grouped subarrays?

Deadly 提交于 2021-01-29 03:00:01
问题 I have an associative array: Array ( [0] => Array ( [term_title] => black ) [1] => Array ( [color_quantity] => 2 ) [2] => Array ( [color_price] => 22 ) [3] => Array ( [term_title] => blue ) [4] => Array ( [color_quantity] => 3 ) [5] => Array ( [color_price] => 33 )) How can I change it into: Array ( [0] => Array ( [term_title] => black, [color_quantity] => 2, [color_price] => 22 ) [1] => Array ( [term_title] => blue, [color_quantity] => 3, [color_price] => 33 ) ) I try the following code: