similar to: select rows with identical columns from a data frame

Displaying 20 results from an estimated 2000 matches similar to: "select rows with identical columns from a data frame"

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 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 ...
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
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 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.
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 >
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 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 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
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 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/
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 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
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,]
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
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
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
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
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/)