Displaying 20 results from an estimated 1000 matches similar to: "plot means ?"
2011 Jul 12
1
how to find out whether a string is a factor?
I have two data frames:
> str(ysmd)
'data.frame': 8325 obs. of 6 variables:
$ X.stock : Factor w/ 8325 levels "A","AA","AA-",..: 2702 6547 4118 7664 7587 6350 3341 5640 5107 7589 ...
$ market.cap : num -1.00 2.97e+10 3.54e+08 3.46e+08 -1.00 ...
$ X52.week.low : num 40.2 22.5 27.5 12.2 20.7 ...
$
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
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
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 Nov 07
3
c weirdness
is there a way to avoid c() appending ".0" and ".1" to seed?
--8<---------------cut here---------------start------------->8---
> c("nons"=1, "seed"=3)
nons seed ## good!
1 3
> c("nons"=1, "seed"=tab[1])
nons seed.0 ## don't want ".0"!
1 2344600
>
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
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.
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 <-
2012 Apr 04
2
recover lost global function
Since R has the same namespace for functions and variables,
> c <- 1
kills the global function, which can be restored by
> c <- get("c",mode="function")
Is there a way to prevent R from overriding globals
or at least warning when I do that
or at least warning when I replace a functional value with non-functional?
thanks.
--
Sam Steingold (http://sds.podval.org/)
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
2012 Aug 27
1
write.matrix.csr data conversion
> write.matrix.csr(mx, y = y, file = file)
> table(y)
0 1
5194394 23487
$ cut -d' ' -f1 f | sort | uniq -c
23487 2
5194394 1
i.e., 0 is written as 1 and 1 is written as 2.
why?
is there a way to disable this?
--
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://palestinefacts.org
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 Aug 24
2
SparseM buglet
read.matrix.csr does not close the connection:
> library('SparseM')
Package SparseM (0.96) loaded.
> read.matrix.csr(foo)
...
Warning message:
closing unused connection 3 (foo)
>
--
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://truepeace.org http://camera.org
http://pmw.org.il http://think-israel.org
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.
--
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
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 Nov 05
1
no method for coercing this S4 class to a vector
all of a sudden, after a SparseM upgrade(?)
I get this error:
> str(z)
Formal class 'matrix.csr' [package "SparseM"] with 4 slots
..@ ra : num [1:85372672] -0.4288 0.0397 0.0104 -0.1843 -0.1203 ...
..@ ja : int [1:85372672] 1 2 3 4 5 6 7 8 9 10 ...
..@ ia : int [1:699777] 1 123 245 367 489 611 733 855 977 1099 ...
..@ dimension: int [1:2] 699776 122
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
2012 Sep 20
1
aggregate help
I want to count attributes of IDs:
--8<---------------cut here---------------start------------->8---
z <- data.frame(id=c(10,20,10,30,10,20),
a1=c("a","b","a","c","b","b"),
a2=c("x","y","x","z","z","y"),
2011 Feb 14
3
help with aggregate()
Hi,
I am trying to aggregate some data and I am confused by the results.
I load a data frame "all" from a csv file, and then I do:
(FOO,BAR,X,Y come from the header line in the csv file,
BTW, how do I rename a column?)
byFOO <- aggregate(list(all$BAR,all$QUUX,all$X/all$Y),
by = list(FOO=all$FOO),
FUN = mean);
I expect a data frame with 4