Displaying 20 results from an estimated 20000 matches similar to: "apply mean to a three-dimension data"
2012 May 22
3
pad leading zeros in front of strings
Dear All,
This question sounds very simple but I don't know where I am wrong. I just want to pad leading zeros in some string, for example, "123" becomes "00123". What is wrong if I do following?
> sprintf("%05s", "123")
[1] " 123"
It didn't return "00123", instead it padded with 'blank'.
Thank you for your help
2012 May 03
2
apply one list to another one
Hi All,
Suppose I have the following codes:
x = data.frame(A = rnorm(20), B = rnorm(20), C = rnorm(20))
a = list()
a[["1.1"]] = x
a[["1.2"]] = x
b = list()
b[["1.1"]] = c("A", "B")
b[["1.2"]] = c("B", "C")
Now I want to apply b to a like this, for each element of 'a', only select the corresponding columns
2011 Feb 25
7
R in different OS
Hi All,
I have two Rs, one has been installed in Windows system and another one has been installed under UNIX system. Is there any environmental variable or function to tell me which R I am using? The reason that I need to know it is under different system, the data path could be different. I want to do something like
if it is R under Windows
path =
2011 Feb 10
2
Repeaded sampling
Hi all,
I have a dataset. Each time I want to sample N(i) elements from it and I want to repeated sampling M times. N(i) is varied from time to time. For example,
dataset = 1:50;
a = list();
M = 1000;
I want to do something like
for(i in 1:M)
{
a[[i]] = sample(dataset,
2011 Aug 30
1
locate the needed columns
Hi All,
I have a data frame, whose colnames like "A.x, B.x, C.x, A.y, B.y, C.y". There could be many columns like this pattern. I want to compare data in columns A.x with A.y, B.x with B.y and C.x with C.y etc.
Suppose my data frame is d,
names(d) = c("A.x", "B.x", "C.x", "A.y", "B.y", "C.y");
If I want to
D1 =
2012 Apr 10
1
re-install a package
Hi All,
I have a self-cooked package and save it to a zip file after running make, say named xxx.zip. After installing it to R by running "Install packages from local zip files" under Packages menu in R (Windows), I realized I needed to change some source codes and re-make it. My question is that if I need re-install that package or R would automatically update the R
2011 Mar 10
1
aggregate by part of a field
Hi All,
I have a data frame like
a = data.frame(date = c(20081201, 20081202, 20081201), product = c("a b c d e", "a b c g h t", "d e h a c e h g"), sales = c(1, 2, 3))
Now I want to aggregate the sales by part of the a$product. 'Product' is the product name, a string separated by a space. The key in my aggregate function is
2013 May 02
2
Self-developed package -- installation
Hi All,
I have a question about package installation in R. We have developed a package, say 'ABC'. We have installed it in two machines, A and B by running 'Install Package(s) from local zip file'. Everything was fine. Right now, suppose that package got damaged in machine A and our zipped file is gone, My question is that may I directly copy ../library/ABC from machine B to
2007 Jan 16
1
curious about dimension of 'apply' output when MARGIN=1
Reading the documentation for 'apply', I understand the following is
working exactly as documented:
> M<-matrix(1:6,ncol=2)
> M
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6
> apply(M,2,function(column) column+c(1,2,3))
[,1] [,2]
[1,] 2 5
[2,] 4 7
[3,] 6 9
> apply(M,1,function(row) row+c(1,2))
[,1] [,2] [,3]
[1,] 2 3 4
2004 Aug 31
2
Dimension of apply(X, MARGIN, FUN) when FUN returns a matrix
Dear all,
apply(X, MARGIN, FUN, ...) returns an array of dimension
c(n, dim(X)[MARGIN]) when FUN returns a vector of length n > 1.
Matrices and arrays are also vectors, so if FUN returns a matrix or an
array, apply returns an array of dimension c(n, dim(X)[MARGIN]) as
above. This is in accordance with the description of apply in the
Blue Book, and also how Splus works (at least v6.0).
I am
2012 Jul 09
1
install.packages
Hi All,
I have two questions regarding install.packages().
Q1: may I run it in non-interactive mode, which means just install the packages I want rather than letting me to choose which mirror etc?
Q2: I ran a R code in batch mode, for example, R CMD BATCH a.r
In a.r, I have some statements like
packages = library()$result[, "Package"];
f(! "plyr" %in% packages)
{
2012 Oct 26
1
backward stepwise model selection
Hi All,
I know in R there is function named 'step', which does the stepwise regression and choose the model by AIC. However, if I want to choose a model per this logic:
1. Run a full model (linear regression, f = lm(y ~., data = ZZZ), for example)
2. Pick up the variable with biggest p value, delete it from the module and get a new regression model.
3. Repeat step 2
2011 Apr 21
3
line type lty
Hi All,
Does somebody know how to know the detail of the line types? For example, lty = 1, means what kind of line?, lty = 2, means what kind of line?
Thanks.
HXD
[[alternative HTML version deleted]]
2013 Jan 24
1
how to read a website with Chinese Character
Hi all,
I am planning to parse some information on a website which includes lots of Chinese characters. Does someone know how to read/display Chinese in R? Thanks.
url = "http://www.teec.org.cn/html/renwujieshao/"
x = readLines(url)
I tried encoding = 'UTF-8' already but it didn't help.
My R version is
$platform
[1] "i386-pc-mingw32"
$arch
[1] "i386"
2012 Jul 11
1
Variance Inflation factor
Hi All,
I need to calculate VIF (variance inflation factor) for my linear regression model. I found there was a function named vif in 'HH' package. I have two questions:
1) I was able to install that package in my R under windows. But while trying to install that package in UNIX, I got error:
Package HH is not available.
Does somebody know why?
2) Does
2011 Feb 16
1
speed up the code
Hi All,
The following is a snippet of my code. It works fine but it is very slow. Is it possible to speed it up by using different data structure or better solution? For 40000 runs, it takes 8 minutes now. Thanks a lot
fun_activation = function(s_k, s_hat, x_k, s_hat_len)
{
common = intersect(s_k, s_hat);
if(length(common) != 0)
{
index = match(common, s_k);
2011 Nov 16
2
apply on rows and columns?
I have the following scenario:
> m <- matrix(1:4, ncol=2)
> m
[,1] [,2]
[1,] 1 3
[2,] 2 4
> apply(m, 2, sum)
[1] 3 7
> apply(m, 1, sum)
[1] 4 6
So I can apply to rows *or* columns. According to the documentation
(?apply)
MARGIN a vector giving the subscripts which the function will be applied
over. E.g., for a matrix 1 indicates rows, 2 indicates columns, c(1,
2012 Nov 06
2
R and SPSS
Hi group:
I have a data set, which has severe colinearity problem. While running linear regression in R and SPSS, I got different models. I am wondering if somebody knows how to make the two software output the same results. (I guess the way R and SPSS handling singularity is different, which leads to different models.)
Thanks.
[[alternative HTML version deleted]]
2002 Jul 02
3
mean and array
In general this is what "apply" does. In your example you could use
rowMeans(ar) as well, I think.
Reid Huntsinger
-----Original Message-----
From: Olivier Martin [mailto:olivier.martin at inrialpes.fr]
Sent: Tuesday, July 02, 2002 10:55 AM
To: r-help
Subject: [R] mean and array
Hi all,
I have an array, one say ar, with 3 dimensions.
dim(ar)
>200 3 4
I would like to
2010 Jan 05
1
variable three dimensional array
I am using R for my bioinformatics research. I am dealing with a graph in
which I need to find all possible path. I was looking for some package that
solve my purpose
but all in vain. There are available algorithms but most of them find
shortest path that ignore other paths So I decided to write my own from
scratch.
I need to create a two dimensional matrix of size nXn.
The element of each entry