Displaying 20 results from an estimated 1000 matches similar to: "what to use for sna/graphs?"
2012 Oct 15
1
Rgraphviz: how to read a "dot" file?
The Rgraphviz package index says nothing about reading "dot" files.
(it has "toFile" to write them but no fromFile).
How do I create an Ragraph object?
(either by reading a dot file or from a list of edges with weights and
vertices with names and other attributes).
--
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/
2013 Jan 04
4
non-consing count
Hi,
to count vector elements with some property, the standard idiom seems to
be length(which):
--8<---------------cut here---------------start------------->8---
x <- c(1,1,0,0,0)
count.0 <- length(which(x == 0))
--8<---------------cut here---------------end--------------->8---
however, this approach allocates and discards 2 vectors: a logical
vector of length=length(x) and an
2012 Dec 04
3
list to matrix?
How do I convert a list to a matrix?
--8<---------------cut here---------------start------------->8---
list(c(50000, 101), c(1e+05, 46), c(150000, 31), c(2e+05, 17),
c(250000, 19), c(3e+05, 11), c(350000, 12), c(4e+05, 25),
c(450000, 19), c(5e+05, 16))
as.matrix(a)
[,1]
[1,] Numeric,2
[2,] Numeric,2
[3,] Numeric,2
[4,] Numeric,2
[5,] Numeric,2
[6,] Numeric,2
[7,]
2012 Aug 28
5
variable scope
At the end of a for loop its variables are still present:
for (i in 1:10) {
x <- vector(length=100000000)
}
ls()
will print "i" and "x".
this means that at the end of the for loop body I have to write
rm(x)
gc()
is there a more elegant way to handle this?
Thanks.
--
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
2012 Aug 10
1
summarize a vector
I have a long numeric vector v (length N) and I want create a shorter
vector of length N/k consisting of sums of k-subsequences of v:
v <- c(1,2,3,4,5,6,7,8,9,10)
N=10, k=3
===> [6,15,24,10]
I can, of course, iterate:
> w <- vector(mode="numeric",length=ceiling(N/k))
> for (i in 1:length(w)) w[i] <- sum(v(i*k:(i+1)*k))
(modulo boundary conditions)
but I wonder if
2011 Feb 15
1
summary for factors is not very informative
summary() for a factor prints:
ColName
SNDK : 72
VXX : 36
MWW : 30
ACI : 28
FRO : 28
(Other):1801
it would have been much more useful if it additionally
printed frequency stats as if by
summary(aggregate(frame$ColName,by=list(frame$ColName),FUN=length)$x)
--
Sam Steingold (http://sds.podval.org/) on CentOS release 5.3 (Final)
http://jihadwatch.org
2013 Apr 21
1
cedta decided 'igraph' wasn't data.table aware
Hi, what does this mean?
--8<---------------cut here---------------start------------->8---
> graph <- graph.data.frame(merged[!v,], vertices=ve, directed=FALSE)
cedta decided 'igraph' wasn't data.table aware
cedta decided 'igraph' wasn't data.table aware
cedta decided 'igraph' wasn't data.table aware
cedta decided 'igraph' wasn't
2012 Nov 09
4
as.data.frame(do.call(rbind,lapply)) produces something weird
The following code:
--8<---------------cut here---------------start------------->8---
> myfun <- function (x) list(x=x,y=x*x)
> z <- as.data.frame(do.call(rbind,lapply(1:3,function(x) c(a=paste("a",x,sep=""),as.list(unlist(list(b=myfun(x),c=myfun(x*x*x))))))))
> z
a b.x b.y c.x c.y
1 a1 1 1 1 1
2 a2 2 4 8 64
3 a3 3 9 27 729
2011 Jul 05
1
hash table access, vector access &c
Hi,
I am confused by the way the indexing works.
I read a table from a csv file like this:
ysmd <- read.csv("ysmd.csv",header=TRUE);
ysmd.table <- hash();
for (i in 1:length(ysmd$X.stock)) ysmd.table[ysmd$X.stock[i]] <- ysmd[i,];
the first column ("X.stock") is a string (factor):
> ysmd$X.stock[[100]]
[1] FLO
7757 Levels: A AA AA- AAAAA AAC AACC AACOU AACOW AADR
2012 Feb 23
5
cor() on sets of vectors
suppose I have two sets of vectors: x1,x2,...,xN and y1,y2,...,yN.
I want N correlations: cor(x1,y1), cor(x2,y2), ..., cor(xN,yN).
my sets of vectors are arranged as data frames x & y (vector=column):
x <- data.frame(a=rnorm(10),b=rnorm(10),c=rnorm(10))
y <- data.frame(d=rnorm(10),e=rnorm(10),f=rnorm(10))
cor(x,y) returns a _matrix_ of all pairwise correlations:
cor(x,y)
2012 Jul 13
1
LiblineaR: read/write model files?
How do I read/write liblinear models to files?
E.g., if I train a model using the command line interface, I might want
to load it into R to look the histogram of the weights.
Or I might want to train a model in R and then apply it using a command
line interface.
--
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/
2012 Oct 16
2
cannot coerce class '"rle"' into a data.frame
why?
> rle
Run Length Encoding
lengths: int [1:1650061] 2 2 8 2 4 5 6 3 26 46 ...
values : chr [1:1650061] "4bbf9e94cbceb70c BG bg" "4fbbf2c67e0fb867 SK sk" ...
> as.data.frame(rle)
Error in as.data.frame.default(vertices.rle) :
cannot coerce class '"rle"' into a data.frame
it seems that
rle.df <-
2012 Sep 19
2
drop zero slots from table?
I find myself doing
--8<---------------cut here---------------start------------->8---
tab <- table(...)
tab <- tab[tab > 0]
tab <- sort(tab,decreasing=TRUE)
--8<---------------cut here---------------end--------------->8---
all the time.
I am wondering if the "drop 0" (and maybe even sort?) can be effected by
some magic argument to table() which I fail to discover
2012 Sep 14
3
aggregate() runs out of memory
I have a large data.frame Z (2,424,185,944 bytes, 10,256,441 rows, 17 columns).
I want to get the result of
table(aggregate(Z$V1, FUN = length, by = list(id=Z$V2))$x)
alas, aggregate has been running for ~30 minute, RSS is 14G, VIRT is
24.3G, and no end in sight.
both V1 and V2 are characters (not factors).
Is there anything I could do to speed this up?
Thanks.
--
Sam Steingold
2012 Dec 27
4
vectorization & modifying globals in functions
I have the following code:
--8<---------------cut here---------------start------------->8---
d <- rep(10,10)
for (i in 1:100) {
a <- sample.int(length(d), size = 2)
if (d[a[1]] >= 1) {
d[a[1]] <- d[a[1]] - 1
d[a[2]] <- d[a[2]] + 1
}
}
--8<---------------cut here---------------end--------------->8---
it does what I want, i.e., modified vector d 100 times.
2012 Nov 07
1
LiblineaR: accept sparse matrices
Thibault,
It would be nice if LiblineaR() accepted data in the form of a sparse
matrix (it does not accept whatever e1071::read.matrix.csr returns).
It would also be nice if there were functions to read/write files in the
native liblinear file format; I am sure the original liblinear library
provides at least the input code.
Thanks!
--
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04
2011 Jul 11
1
plot means ?
Hi,
I need this plot:
given: x,y - numerical vectors of length N
plot xi vs mean(yj such that |xj - xi|<epsilon)
(running mean?)
alternatively, discretize X as if for histogram plotting and plot mean y
over the center of the histogram group.
is there a simple way?
thanks!
--
Sam Steingold (http://sds.podval.org/) on CentOS release 5.6 (Final) X 11.0.60900031
http://thereligionofpeace.com
2012 Aug 15
3
per-vertex statistics of edge weights
I have a graph with edge and vertex weights, stored in two data frames:
--8<---------------cut here---------------start------------->8---
vertices <- data.frame(vertex=c("a","b","c","d"),weight=c(1,2,1,3))
edges <-
2011 Jul 12
3
when to use `which'?
when do I need to use which()?
> a <- c(1,2,3,4,5,6)
> a
[1] 1 2 3 4 5 6
> a[a==4]
[1] 4
> a[which(a==4)]
[1] 4
> which(a==4)
[1] 4
> a[which(a>2)]
[1] 3 4 5 6
> a[a>2]
[1] 3 4 5 6
>
seems unnecessary...
--
Sam Steingold (http://sds.podval.org/) on CentOS release 5.6 (Final) X 11.0.60900031
http://jihadwatch.org http://palestinefacts.org http://mideasttruth.com
2012 Feb 10
2
naiveBayes: slow predict, weird results
I did this:
nb <- naiveBayes(users, platform)
pl <- predict(nb,users)
nrow(users) ==> 314781
ncol(users) ==> 109
1. naiveBayes() was quite fast (~20 seconds), while predict() was slow
(tens of minutes). why?
2. the predict results were completely off the mark (quite the opposite
of the expected overfitting). suffice it to show the tables:
pl:
android blackberry ipad