combn

How to remove correlated variables from GLM in R

五迷三道 提交于 2019-12-25 09:49:13
问题 I am trying to exclude correlated variables from GLModel. Firstly, I calculate correlation matrix. Afterwards, I would like to implement it into combn function in some way to exclude the variables (column headers) that are correlated. At this point I fail - I am not able to incorporate it in combn function so that it worked and correlated variables were excluded. Here is the link for data I use: https://drive.google.com/open?id=0B5IgiR_svnKcZkxHeTJXTm9jUjQ Here is the code I am trying to make

Generate all unique combinations from a vector with repeating elements

China☆狼群 提交于 2019-12-23 10:49:17
问题 This questions was asked previously but only for vectors with non-repeating elements. I was not able to find an easy solution to get all combinations from a vector with repeating elements. To illustrate I listed an example below. x <- c('red', 'blue', 'green', 'red', 'green', 'red') Vector x has 3 repeating elements for 'red' and 2 for 'green'. The expected outcome for all unique combinations would be like this. # unique combinations with one element 'red' 'blue' 'green' # unique combination

Get unique combination (combn) by ID in R

随声附和 提交于 2019-12-12 03:43:06
问题 I try to get unique combination by each ID, I keep get error, it doesn't expand ID. ID <- c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,4,4,4,5,5,5,5,5,6,6,6,6) var1 <- c("A","B","E","F","C","D","C","A","B","C","A","D","B","C", "A","B","C","A","D","C","A","B","C","E","F","G") df1 <- data.frame(ID,var1) df1 <- df1[order(df1$ID, df1$var1),] dd <- unique(df1) dd <- data.table(dd) dd[,new4 := t(combn(sort(var1), m = 3))[,1],by= "ID"] dd[,new5:= t(combn(sort(var1), m = 3))[,2],by="ID"] dd[,new6:= t(combn(sort

meaning of combn error: Error in FUN(X[[i]], …) : n < m in R

怎甘沉沦 提交于 2019-12-12 02:53:56
问题 Trying to create a pair of element but get the following error: Error in FUN(X[[i]], ...) : n < m The error appears after running the code: rslt <- lapply(split(my$symbol, my$character), combn, 2, simplify = F) Here my is my data frame and symbol and character is column of data frame. the data frame contain 26,552 rows. Here i posted the small part of my data. my: symbol character BHMT Abruptio Placentae BHMT Diabetes Mellitus, Type 2 BHMT Lymphoma, Non-Hodgkin BHMT Neural Tube Defects BID

Creating Dataframes of all Possible Combinations without Repetition of Columns with cbind

谁说我不能喝 提交于 2019-12-10 23:04:59
问题 I have 3 data frames that each look like this: head(New_Re) JPM.GBI.GLOBAL MSCI.WORLD.U MSCI.EM.U WORLD.DS.Market EMERGING.MARKETS.DS S.P.GSCI HFRI.FUND.WEIGHTED 2000-01-31 -0.23666947 -0.68583345 0.07151953 -0.5730685 0.27303054 0.8676359 0.07679939 2000-02-29 -0.06022908 0.03385849 0.15848440 0.1591570 -0.06121937 0.7497046 0.73921129 2000-03-31 0.34922825 0.83091828 0.05856337 0.6840922 0.12306658 -0.1392837 0.11159392 2000-04-28 -0.36499225 -0.50602011 -1.13751290 -0.7176648 -1.18921618

Set column names while calling a function

匆匆过客 提交于 2019-12-09 21:10:05
问题 Consider we have a numeric data.frame foo and want to find the sum of each two columns: foo <- data.frame(x=1:5,y=4:8,z=10:14, w=8:4) bar <- combn(colnames(foo), 2, function(x) foo[,x[1]] + foo[,x[2]]) bar # [,1] [,2] [,3] [,4] [,5] [,6] #[1,] 5 11 9 14 12 18 #[2,] 7 13 9 16 12 18 #[3,] 9 15 9 18 12 18 #[4,] 11 17 9 20 12 18 #[5,] 13 19 9 22 12 18 Everything is fine, except the column names that are missing from bar . I want column names of bar to show the related columns in foo , for

R find all possible unique combinations

送分小仙女□ 提交于 2019-12-08 07:24:35
问题 I am trying to find all possible unique combinations in R. It seems that there have been a lot of similar questions asked, but I was not able to find the same one. My question is to find combinations of m number of elements from vector x, but m could be larger than x. For example, pick 3 elements from letters[1:2], which hopefully can return: combn(letters[1:2],3) [,1] [,2] [,3] [,4] [1,] "a" "a" "a" "b" [2,] "a" "a" "b" "b" [3,] "a" "b" "b" "b" But instead error in combn function n < m.

R: how to perform more complex calculations from a combn of a dataset?

社会主义新天地 提交于 2019-12-07 03:46:16
问题 Right now, I have a combn from the built in dataset iris. So far, I have been guided into being able to find the coefficient of lm() of the pair of values. myPairs <- combn(names(iris[1:4]), 2) formula <- apply(myPairs, MARGIN=2, FUN=paste, collapse="~") model <- lapply(formula, function(x) lm(formula=x, data=iris)$coefficients[2]) model However, I would like to go a few steps further and use the coefficient from lm() to be used in further calculations. I would like to do something like this:

Set column names while calling a function

我们两清 提交于 2019-12-04 18:09:45
Consider we have a numeric data.frame foo and want to find the sum of each two columns: foo <- data.frame(x=1:5,y=4:8,z=10:14, w=8:4) bar <- combn(colnames(foo), 2, function(x) foo[,x[1]] + foo[,x[2]]) bar # [,1] [,2] [,3] [,4] [,5] [,6] #[1,] 5 11 9 14 12 18 #[2,] 7 13 9 16 12 18 #[3,] 9 15 9 18 12 18 #[4,] 11 17 9 20 12 18 #[5,] 13 19 9 22 12 18 Everything is fine, except the column names that are missing from bar . I want column names of bar to show the related columns in foo , for instance in this example: colnames(bar) <- apply(combn(colnames(foo),2), 2, paste0,collapse="") colnames(bar)