Displaying 20 results from an estimated 1000 matches similar to: "removing NA from a data frame"
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
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")
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
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
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 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 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)
2017 Nov 09
2
[R-pkgs] Release of ess 0.0.1
> * Jorge Cimentada <pvzragnqnw at tznvy.pbz> [2017-11-09 00:02:53 +0100]:
>
> I'm happy to announce the release of ess 0.0.1 a package designed to
> download data from the European Social Survey
Given the existence of ESS (Emacs Speaks Statistics -
https://ess.r-project.org/) the package name "ess" seems unfortunate.
--
Sam Steingold (http://sds.podval.org/) on
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 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 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"),
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
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/)
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 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
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 <-
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 13
1
entropy package: how to compute mutual information?
suppose I have two factor vectors:
x <- as.factor(c("a","b","a","c","b","c"))
y <- as.factor(c("b","a","a","c","c","b"))
I can compute their entropies:
entropy(table(x))
[1] 1.098612
using
library(entropy)
but it is not clear how to compute their mutual information
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 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