Finding all pair combinations in strings with several comma separated instances in R -


i'm new r , trying solve a, me, challenging problem.

i have .csv file containing 22.388 rows comma separated integers. want find possible combinations of pairs of integers each row separately , list them pair pair, i'll able make visual representation of them clusters.

i've tried installing combinat package r can't seem solve problem.

an example file be

2 13

2 8 6

which should listed in possible combinations of pairs this.

2, 13
2, 8
2, 6
8, 6

sample input - replace textconnection(...) csv filename.

csv <- textconnection("2,13 2,8,6") 

this reads input list of values:

input.lines  <- readlines(csv) input.values <- strsplit(input.lines, ',') 

this creates nested list of pairs:

pairs <- lapply(input.values, combn, 2, simplify = false) 

this puts in nice matrix of integers:

pairs.mat <- matrix(as.integer(unlist(pairs)), ncol = 2, byrow = true) pairs.mat #      [,1] [,2] # [1,]    2   13 # [2,]    2    8 # [3,]    2    6 # [4,]    8    6 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -