Displaying 20 results from an estimated 6000 matches similar to: "extract fixed width fields from a string"
2011 Dec 21
4
qqnorm & huge datasets
Hi,
When qqnorm on a vector of length 10M+ I get a huge pdf file which
cannot be loaded by acroread or evince.
Any suggestions? (apart from sampling the data).
Thanks.
--
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://mideasttruth.com http://honestreporting.com http://camera.org
http://openvotingconsortium.org http://pmw.org.il
2012 Mar 14
2
sum(hist$density) == 2 ?!
> x <- rnorm(1000)
> h <- hist(x,plot=FALSE)
> sum(h$density)
[1] 2 ----------------------------- shouldn't it be 1?!
> h <- hist(x,plot=FALSE, breaks=(-4:4))
> sum(h$density)
[1] 1 ----------------------------- now it's 1. why?!
--
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.childpsy.net/ http://www.memritv.org
2006 May 11
3
cannot turn some columns in a data frame into factors
Hi,
I have a data frame df and a list of names of columns that I want to
turn into factors:
df.names <- attr(df,"names")
sapply(factors, function (name) {
pos <- match(name,df.names)
if (is.na(pos)) stop(paste(name,": no such column\n"))
df[[pos]] <- factor(df[[pos]])
cat(name,"(",pos,"):",is.factor(df[[pos]]),"\n")
2012 Aug 30
3
apply --> data.frame
Is there a way for an apply-type function to return a data frame?
the closest thing I think of is
foo <- as.data.frame(sapply(...))
names(foo) <- c(....)
is there a more "elegant" way?
Thanks!
--
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://palestinefacts.org http://dhimmi.com
http://honestreporting.com
2012 Feb 08
4
"unsparse" a vector
Suppose I have a vector of strings:
c("A1B2","A3C4","B5","C6A7B8")
[1] "A1B2" "A3C4" "B5" "C6A7B8"
where each string is a sequence of <column><value> pairs
(fixed width, in this example both value and name are 1 character, in
reality the column name is 6 chars and value is 2 digits).
I need to
2006 Mar 17
6
removing NA from a data frame
Hi,
It appears that deal does not support missing values (NA), so I need to
remove them (NAs) from my data frame.
how do I do this?
(I am very new to R, so a detailed step-by-step
explanation with code samples would be nice).
Some columns (variables) have quite a few NAs, so I would rather drop
the whole column than sacrifice all the rows (observations) which have
NA in that column.
How do I
2012 Apr 04
2
plot with a regression line(s)
I am sure a common need is to plot a scatterplot with some fitted
line(s) and maybe save to a file.
I have this:
plot.glm <- function (x, y, file = NULL, xlab = deparse(substitute(x)),
ylab = deparse(substitute(y)), main = NULL) {
m <- glm(y ~ x)
if (!is.null(file))
pdf(file = file)
plot(x, y, xlab = xlab, ylab = ylab, main = main)
lines(x, y =
2013 Jan 18
5
select rows with identical columns from a data frame
I have a data frame with several columns.
I want to select the rows with no NAs (as with complete.cases)
and all columns identical.
E.g., for
--8<---------------cut here---------------start------------->8---
> f <- data.frame(a=c(1,NA,NA,4),b=c(1,NA,3,40),c=c(1,NA,5,40))
> f
a b c
1 1 1 1
2 NA NA NA
3 NA 3 5
4 4 40 40
--8<---------------cut
2011 Feb 15
2
strptime format = "%H:%M:%OS6"
I read a dataset with times in them, e.g., "09:31:29.18761".
I then parse them:
> all$X.Time <- strptime(all$X.Time, format = "%H:%M:%OS6");
and get a vector of NAs (how do I check that except for a visual inspection?)
then I do
> options("digits.secs"=6);
> all$X.Time <- strptime(all$X.Time, format = "%H:%M:%OS");
and it, apparently, works:
2012 Mar 20
2
igraph: decompose.graph: Error: protect(): protection stack overflow
I just got this error:
> library(igraph)
> comp <- decompose.graph(gr)
Error: protect(): protection stack overflow
Error: protect(): protection stack overflow
>
what can I do?
the digraph is, indeed, large (300,000 vertexes), but there are very
many very small components (which I would rather not discard).
PS. the doc for decompose.graph does not say which mode is the default.
--
2012 Oct 18
3
how to concatenate factor vectors?
How do I concatenate two vectors of factors?
--8<---------------cut here---------------start------------->8---
> a <- factor(5:1,levels=1:9)
> b <- factor(9:1,levels=1:9)
> str(c(a,b))
int [1:14] 5 4 3 2 1 9 8 7 6 5 ...
> str(unlist(list(a,b),use.names=FALSE))
Factor w/ 9 levels "1","2","3","4",..: 5 4 3 2 1 9 8 7 6 5 ...
2011 Aug 16
2
merge(join) problem
I have two datasets:
A with columns Open and Name (and many others, irrelevant to the merge)
B with columns Time and Name (and many others, irrelevant to the merge)
I want the dataset AB with all these columns
Open from A - a difftime (time of day)
Time from B - a difftime (time of day)
Name (same in A & B) - a factor, does NOT index rows, i.e., there are
_many_ rows in both A & B with
2011 Feb 15
4
string parsing
I am trying to get stock metadata from Yahoo finance (or maybe there is
a better source?)
here is what I did so far:
yahoo.url <- "http://finance.yahoo.com/d/quotes.csv?f=j1jka2&s=";
stocks <- c("IBM","NOIZ","MSFT","LNN","C","BODY","F"); # just some samples
socket <-
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
2012 Oct 07
2
a merge() problem
I know it does not look very good - using the same column names to mean
different things in different data frames, but here you go:
--8<---------------cut here---------------start------------->8---
> x <- data.frame(a=c(1,2,3),b=c(4,5,6))
> y <- data.frame(b=c(1,2),a=c("a","b"))
>
2011 Feb 15
1
all.equal: subscript out of bounds
When I do
> all(all$X.Time == all$Y.Time);
[1] TRUE
as expected, but
> all.equal(all$X.Time,all$Y.Time);
Error in target[[i]] : subscript out of bounds
why?
thanks!
--
Sam Steingold (http://sds.podval.org/) on CentOS release 5.3 (Final)
http://mideasttruth.com http://honestreporting.com http://dhimmi.com
http://jihadwatch.org http://pmw.org.il http://ffii.org
The dark past once was the
2012 Sep 19
4
where are these NAs coming from?
I see this:
--8<---------------cut here---------------start------------->8---
> length(which(is.na(z$language)))
[1] 0
> locals <- z[z$country == mycountry,]
> length(which(is.na(locals$language)))
[1] 229
--8<---------------cut here---------------end--------------->8---
where are those locals without the language coming from?!
--
Sam Steingold (http://sds.podval.org/) on
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 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
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 <-