Displaying 20 results from an estimated 48 matches for "subset2".
Did you mean:
subset
2007 Jul 12
1
[[.data frame and row names
Hi,
I'm wondering why indexing a data frame by row name doesn't work
with [[. It works with [:
> sw <- swiss[1:5,1:2]
> sw["Moutier", "Agriculture"]
[1] 36.5
but not with [[:
> sw[["Moutier", "Agriculture"]]
Error in .subset2(.subset2(x, ..2), ..1) : subscript out of bounds
The problem is really with the row name (and not the col name) since
this works:
> sw[[4, "Agriculture"]]
[1] 36.5
but not this:
> sw[["Moutier", 2]]
Error in .subset2(.subset2(x, ..2), ..1) : subscript out of bo...
2010 Nov 18
3
problems subsetting
...but it returns an empty data frame.
Anyway, the main problem is
Problem2:
I have a second data frame - a square matrix (rownames == colnames), distm:
distm<-read.table(file=f_simmatrix, sep = ",");
what I want is select ONLY the columns and rows entries matching the
above subset1:
subset2<-distm[subset1$Dataset,subset1$Dataset] returns a matrix of
correct size, but with incorrect entries (established by visual inspection).
this is the same as:
selectedrows<-as.vector(subset1$Dataset)
subset2<-distm[selectedrows,selectedrows]
also verified using:
rownames(subset2)%in% sel...
2020 Jun 17
2
subset data.frame at C level
Hi,
Hope you are well.
I was wondering if there is a function at C level that is equivalent to
mtcars$carb or .subset2(mtcars, "carb").
If I have the index of the column then the answer would be VECTOR_ELT(df,
asInteger(idx)) but I was wondering if there is a way to do it directly
from the name of the column without having to loop over columns names to
find the index?
Thank you
Best regards
Morgan
[[a...
2011 Feb 24
1
Creating objects (data.frames) with names stored in character vector
...tive names which I have stored in a character vector. My original thought was that I want the subsets to show up as individual objects, but haveing them stored in a list is fine (maybe better).
I can create a list of subsetted data.frames like this:
>Lst = list(subset1 = (subset (blablabla)), subset2 = (subset(blabla)))
but I have to provide the component names (subset1, subset2) manually.
I would like to pull the component names from an existing character vector, but so far my attempts have failed.
Any advice is appreciated, even if the advice is "don't do that."
Thank you,
K...
2007 Oct 14
1
bug (?) in [.data.frame with matrix-like indexing
Consider in R-2.6.0 (also R-patched from yesterday):
iris[1, c(TRUE, FALSE, FALSE, FALSE, FALSE)]
## Error in .subset2(xx, j) : recursive indexing failed at level 2
iris[1, c(FALSE, FALSE, FALSE, FALSE, TRUE)]
## Error in .subset2(xx, j) : attempt to select less than one element
i.e. matrix-like indexing on data.frames, one logically-indexed
dimension with only one value TRUE in it.
It is not documented to work...
2008 Jul 01
1
[.data.frame speedup
...d columns selected")
if (any(duplicated(cols)))
names(y) <- make.unique(cols)
return(structure(y, class = oldClass(x),
row.names = .row_names_info(x, 0L)))
}
if (missing(i)) {
if (missing(j) && drop && length(x) == 1L)
return(.subset2(x, 1L))
y <- if (missing(j))
x
else .subset(x, j)
if (drop && length(y) == 1L)
return(.subset2(y, 1L))
cols <- names(y)
if (any(is.na(cols)))
stop("undefined columns selected")
if (any(duplicated(cols)))
names(y) <- make.uni...
2024 Feb 29
0
Low level subsetting and S3 subsetting
Dear R-devel,
I periodically stumble on the same challenges when working with objects
with bracket S3 methods, and their length and names counterparts. I make
the distinction between what I call S3 subsetting using `[` and `[[` and
low level subsetting using `.subset()` and `.subset2()`.
When working with low level subsetting one has to be extremely careful,
because `length()`, `names()`, and `lapply()` (through the `as.list()`
method) are not guaranteed to work consistently (they are technically not
guaranteed to work consistently at the S3 level either but I reckon that
for...
2009 Sep 13
1
Manage an unknown and variable number of data frames
...ltsDF = as.data.frame(CutResults)
head(CutResultsDF, n=15)
dat$aRange = CutResultsDF$a
dat$bRange = CutResultsDF$b
head(dat, 15)
# I don't want to do the following as it doesn't
# get managed automatically.
Subset1 = subset(subset(dat, aRange==CutTable$a[1]), bRange==CutTable$b[1])[1:2]
Subset2 = subset(subset(dat, aRange==CutTable$a[2]), bRange==CutTable$b[2])[1:2]
Subset3 = subset(subset(dat, aRange==CutTable$a[3]), bRange==CutTable$b[3])[1:2]
Subset4 = subset(subset(dat, aRange==CutTable$a[4]), bRange==CutTable$b[4])[1:2]
Subset1
Subset2
Subset3
Subset4
CutTable
2012 Apr 21
2
using "factor" to eliminate unused levels without dropping other variables
...39;sample_x' &
Sample !='sample_y')).
**This leaves me a data file that has 8 levels of the variable
"Sample" and 2 empty levels that correspond to sample_x and sample_y.
I need to get rid of these two levels for plotting purposes, so I
tried using the code below...
data.subset2 <- factor(data.subset1$Sample)
**This does get rid of the two empty levels, but also gets rid of all
the other variables in the dataset, which I want to keep. So my
question is, how do I accomplish getting rid of the empty levels,
while retaining the other variables in the dataset?? I tried the...
2004 Dec 14
1
Multiple options for a package
...ing myselft what would be the "better" strategy to handle a bunch
of options for a package.
I ended up with the idea of storing a list, as my options would also be
classified, with something like:
--
MyPkgOptions =
list(set1=list(par1=1,par2=2),set2=list(subset1=list(par1=11,par2=22),subset2=list(par1=111,par2=222)))
options(PkgName=MyPkgOptions)
--
Then, to make easier the access to an element, I tweaked a little bit
getOption, with the following version:
--
getOption <- function(x,...)
{
op = options(x)[[1]]
if (length(list(...))>0) op <- op[[c(...)]]
return(op)...
2012 Sep 06
1
use of ddply() within function
...er these categories).
The function fails in the following line:
COSTaux_AVCAR <- ddply(CARaux,c("SC","YEAR"),summarize,costcsolo = sum(CARaux[[costcarin]]))
With the following error message:
Error in (function(x, i, exact) if (is.matrix(i)) as.matrix(x)[[i]] else .subset2(x, :
object 'costcarin' not found
When I debugged the function, I found the following:
Browse[1]> costcarin
[1] "CS_MONCOST_EXCLTAXCAR"
Browse[1]> summary(CARaux[[costcarin]])
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.0000000 0.0000000 0.0001605 0.01...
2018 Aug 24
5
True length - length(unclass(x)) - without having to call unclass()?
Is there a low-level function that returns the length of an object 'x'
- the length that for instance .subset(x) and .subset2(x) see? An
obvious candidate would be to use:
.length <- function(x) length(unclass(x))
However, I'm concerned that calling unclass(x) may trigger an
expensive copy internally in some cases. Is that concern unfounded?
Thxs,
Henrik
2007 Oct 22
2
Help interpreting output of Rprof
...0.2 0.56 0.2
Rank 0.54 0.2 23.18 6.8
!= 0.54 0.2 0.54 0.2
: 0.52 0.2 0.52 0.2
- 0.46 0.1 0.46 0.1
as.vector 0.44 0.1 0.44 0.1
.subset2 0.36 0.1 0.36 0.1
min 0.34 0.1 0.34 0.1
seq_along 0.34 0.1 0.34 0.1
max 0.32 0.1 0.32 0.1
is.data.frame 0.24 0.1 1.72 0.5
is.character 0.18 0.1...
2009 Oct 19
2
how to get rid of 2 for-loops and optimize runtime
...0.80 0.6 0.80 0.6
levels.default 0.68 0.5 0.76 0.6
all 0.62 0.5 0.62 0.5
< 0.54 0.4 0.54 0.4
- 0.48 0.4 0.48 0.4
is.factor 0.44 0.3 2.34 1.8
.subset2 0.38 0.3 0.38 0.3
attr 0.36 0.3 0.36 0.3
is.character 0.28 0.2 0.28 0.2
is.null 0.28 0.2 0.28 0.2
| 0.26 0.2 0.26 0.2
oldClass<- 0.20 0.2 0.20 0.2...
2020 Jun 23
0
subset data.frame at C level
It looks to me like internally .subset2 uses `get1index()`, but this
function is declared in Defn.h, which AFAIK is not part of the exported R
API.
Looking at the code for `get1index()` it looks like it just loops over the
(translated) names, so I guess I just do that [0].
[0]:
https://github.com/r-devel/r-svn/blob/1ff1d4197495a6ee1e1...
2009 Dec 12
1
code for [[.data.frame
Hello.
I'm currently trying to wrap up data frames into OCaml via OCaml-R, and
I'm having trouble with data frame subsetting:
> # x#column 1;;
> Erreur dans (function(x, i, exact) if (is.matrix(i)) as.matrix(x)[[i]] else .subset2(x, :
> l'?l?ment 1 est vide ;
> la partie de la liste d'arguments de 'is.matrix' en cours d'?valuation ?tait :
> (i)
So I'd like to know what is the code of [[.data.frame. I know how to
show the code of functions in R (just typing the name of the function)...
2014 Jan 24
1
Format an empty data frame
Hi,
Here seems to be a corner case in which format() fails:
> format(data.frame())
Error in .subset2(x, i, exact = exact) : subscript out of bounds
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
LC_P...
2011 Nov 09
2
plot separate groups with plotmeans()
...g
variable is included in the formula argument.
For instance,
> require(gplots)
> x <- data.frame(Score=rnorm(100), Time=rep(1:10, 10),
Group=factor(rep(c("A","B"),50)))
> plotmeans(Score ~ Time, x) #works fine
> plotmeans(Score ~ Time * Group, x)
Error in .subset2(x, i, exact = exact) :
attempt to select more than one element
> plotmeans(Score ~ Time | Group, x)
Error in ns - 1 : non-numeric argument to binary operator
In addition: Warning message:
In Ops.factor(Time, Group) : | not meaningful for factors
The help for plotmeans() states that it accep...
2007 May 31
0
Merging two data objects question
I have two R objects, allDataSubset1 and allDataSubset2 and the str of
both of them is shown below ( I don't show all 18 lists for
space purposes ). The difference between them is that the times ( and
possibly the days ) and the data is different and what I want to do is
merge them so that only the data in Subset2 that is the same day and
times as S...
2006 Mar 07
3
Making an S3 object act like a data.frame
"[.ggobiDataset" <- function(x, ..., drop=FALSE) {
x <- as.data.frame(x)
NextMethod("[", x)
}
"[[.ggobiDataset" <- function(x, ..., drop=FALSE) {
x <- as.data.frame(x)
NextMethod("[[", x)
}
"$.ggobiDataset" <- function(x, ..., drop=FALSE) {
x <- as.data.frame(x)
NextMethod("$", x)
}
> class(x)
[1]