Displaying 20 results from an estimated 5000 matches similar to: "list matching"
2007 Jan 09
5
a question of substitute
Hi all,
I want to write a wrapper for an analysis of variance and I face a curious
problem. Here are two different wrappers:
fun.1 <- function(formula) {
summary(aov(formula))
}
fun.2 <- function(formula) {
oneway.test(formula)
}
values <- c(15, 8, 17, 7, 26, 12, 8, 11, 16, 9, 16,
24, 20, 19, 9, 17, 11, 8, 15, 6, 14)
group <- rep(1:3, each=7)
# While the first
2005 Nov 21
4
attributes of a data.frame
Dear all,
I noticed that a data.frame has four attributes:
- names
- row.names
- class
- variable.labels
While one can use the first three (i.e. names(foo) or class(foo)), the fourth
one can only be used via:
attributes(foo)$variable.labels
(which is kind of a tedious thing to type)
Is it or would be possible to simply use:
variable.labels(foo)
like the first three attributes?
I tried:
varlab
2007 Jan 30
6
jump in sequence
Dear list,
This should be a simple one, I just cannot see it.
I need to generate a sequence of the form:
4 5 6 13 14 15 22 23 24
That is: starting with 4, make a 3 numbers sequence, jump 6, then another 3
and so on.
I can create a whole vector with:
myvec <- rep(rep(c(F, T, F), rep(3, 3)), 3)
Then see which are TRUE:
which(myvec)
[1] 4 5 6 13 14 15 22 23 24
I'd like to avoid
2006 Aug 09
3
objects and environments
Dear list,
I have two functions created in the same environment, fun1 and fun2.
fun2 is called by fun1, but fun2 should use an object which is created in fun1
fun1 <- function(x) {
ifelse(somecondition, bb <- "o", bb <- "*")
## mymatrix is created, then
myresult <- apply(mymatrix, 1, fun2)
}
fun2 <- function(idx) {
if (bb == "o) {
#
2007 Jan 21
2
multiple bases to decimal (was: comparing two matrices)
Hi again,
I was contemplating the solution using base 3:
set.seed(3)
mat2 <- matrix(sample(0:2, 15, replace=T), 5, 3)
Extracting the line numbers is simple:
bases <- c(3, 3, 3)^(2:0) # or just 3^(2:0)
colSums(apply(mat2, 1, function(x) x*bases)) + 1
[1] 7 23 25 8 1
The problem is sometimes the columns have different number of levels, as in:
mat1 <- expand.grid(0:2, 0:2,
2007 May 29
2
pie initial angle
Dear all,
I'd like to produce a simple pie chart for a customer (I know it's bad but
they insist), and I have some difficulties setting the initial angle.
For example:
pie(c(60, 40), init.angle=14)
and
pie(c(80, 20), init.angle=338)
both present the slices in the same direction, where:
pie(c(60, 40))
pie(c(80, 20))
present the slices in different directions.
I read everything I
2006 Oct 14
1
weight cases?
Dear all,
This is probably a stupid question for which I have a solution, which
unfortunately is not as straighforward as I'd like. I wonder if there's a
simple way to apply a weighting variable for the cases of a dataframe (well
I'm sure there is, I just cannot find it).
My toy example:
> my.data <- data.frame(var1=c("c", "e", "a",
2007 Nov 14
4
library path in Rd link
Dear all,
When creating new functions in a package, there is a "See also" component in
the Rd file.
Usually one uses \link{otherfun}, if the other function is from the same
package, or \link[otherpackage]{otherfun} otherwise.
The trouble is that I install new packages not in the default R library
folder, but into some other subfolder in my home, so the link searches
for
2012 Apr 05
2
"NA" vs. NA
Dear All,
I assume this is an R-devel issue, apologies if I missed something
obvious. I have a dataframe where the row names are country codes,
based on ISO 3166, something like this:
------------
"v1" "v2"
"UK" 1 2
"NA" 2 3
------------
It happens that "NA" is the country code for "Namibia", and that
creates problems on
2004 Oct 13
3
one more Rcmdr problem
Hello,
I'm using R 2.0.0 with the latest Rcmdr package installed from CRAN, on
Windows XP Professional.
When trying to copy some commands or results, either from the upper or lower
text window, this causes Rcmdr to crash:
"R for Windows GUI front-end has encountered a problem and needs to close"
Did anyone have the same problem? I don't think it's my system, as it
2004 Oct 13
3
one more Rcmdr problem
Hello,
I'm using R 2.0.0 with the latest Rcmdr package installed from CRAN, on
Windows XP Professional.
When trying to copy some commands or results, either from the upper or lower
text window, this causes Rcmdr to crash:
"R for Windows GUI front-end has encountered a problem and needs to close"
Did anyone have the same problem? I don't think it's my system, as it
2005 Sep 09
1
measurement unit
Dear R-list,
Could anybody tell me where to find information about changing the measurement
unit from inch to centimeters?
I read the help from X11, I read R-intro and I did some searhing in the R
archives, but I couldn't find the answer.
For example, I would like to produce a plot of a certain width and height:
X11(width=10, height=5)
and I would like these to be centimeters, rather
2006 Mar 10
2
ifelse problem
Dear all,
There is something I'm missing in order to understand the following behavior:
> aa <- c("test", "name")
> ifelse(any(nchar(aa) < 3), aa[-which(nchar(aa) < 3)], aa)
[1] "test"
> any(nchar(aa) < 3)
[1] FALSE
Shouldn't the ifelse function return the whole aa vector?
Using if and else separately, I get the correct result...
>
2007 Dec 16
1
read.table and double quotes in strings
Dear all,
Some very wise data entry person gave me about an hour of a headache, trying
to find out why a 2000x500 dataframe won't be read into R.
After much trial and error, I pinpointed the problem to an accidentally
inserted double quote into a string variable (some comments from an open
question). This can be replicated by:
aa <- data.frame(id=1:2, var1=c("some \"
2014 Jun 16
1
index.search
Dear r-devel,
I am trying to automatically check if two successive versions of a
package have the same results (i.e. code not broken), by parsing the
example sections for each function against a previously tested
version.
While trying to replicate the code from example(), I am facing an
error related with te "index.search" function (line 7 in the example()
code).
This is the code I am
2009 Apr 10
4
split a character variable into several character variable by a character
Dear Mao Jianfeng,
"r-help-owner" is not the place for help, but:
r-help at r-project.org
(CC-ed here)
In any case, strsplit() does the job, i.e.:
> unlist(strsplit("BCPy01-01", "-"))
[1] "BCPy01" "01"
You can work with the whole variable, like:
splitpop <- strsplit(df1$popcode, "-")
then access the first part with
>
2007 Sep 16
1
programming question
Dear list,
I have a vector of numbers, let's say:
myvec <- c(2, 8, 24, 26, 51, 57, 58, 78, 219)
My task is to reduce this vector to non-reducible numbers; small numbers can
cross-out some of the larger ones, based on a function let's say called
reduce()
If I apply the function to the first element 2, my vector gets shorted to:
> (myvec <- reduce(myvec[1]))
[1] 2 24 51
2004 May 27
4
extract columns using their names
Hello,
Is there a way to extract multiple columns from a dataframe using their
names instead of their numbers?
Currently I use:
data2 <- data1[, c(1,3,9)]
And I am looking for something like
data2 <- data1[, c("XX","YY","ZZ")]
I use the same dataframe for many purposes, and I run codes that change
the order of the columns every time.
Many thanks,
Adrian
2007 Nov 15
3
generate combination set
I have a set data={A,B,C,D,E,F,G}
I want to choose 2 letter from 8 letters, i.e. generate the combination set
for choose 2 letters from 8 letters.
I want to get the liking:
combination set={AB,AC,AD,....}
Does anyone konw how to do in R.
thanks,
Aimin
2005 Nov 19
5
help with apply, please
Dear list,
I have a problem with a toy example:
mtrx <- matrix(c(1,1,0,1,1,1,0,1,1,0,0,1), nrow=3)
rownames(ma) <- letters[1:3]
I would like to determine which is the minimum combination of rows that
"covers" all columns with at least a 1.
None of the rows covers all columns; all three rows clearly covers all
columns, but there are simpler combinations (1st and the 3rd, or 2nd