Displaying 20 results from an estimated 7000 matches similar to: "rowSums() and is.integer()"
2004 Nov 08
1
conv() example in R-exts
Hi
[I'm not sure if this is "intelligible to non-programmers" or not]
R-exts (section 4.2) gives an example of the .C() function whose
third argument is
"as.integer(length(a))",
and urges the user to coerce all the arguments to the correct form
(on pain of "hard-to-catch errors"
which I now know to be very appropriate, if understated, phrasing).
The
2005 Feb 07
4
proportional matrix rows
Hi
I have a two-column integer matrix like this:
R> jj
[,1] [,2]
[1,] -1 1
[2,] -2 2
[3,] -7 6
[4,] -8 7
[5,] -6 5
[6,] -9 8
[7,] -5 4
[8,] 3 -3
[9,] -10 9
[10,] -4 3
I want a diagnostic that detects whether a row is a multiple of
the first row or not. In this case, this would be rows 1,2, and 8.
How to do this
2004 Sep 08
3
do.call("[", ...) question
Hi again everyone
I have an arbitrarily dimensional array "a" and a list "jj" of length
length(dim(a)). The elements of jj are vectors of indexes.
How do I use do.call() to extract a[ jj[[1]], jj[[2]], jj[[3]], ...] ?
Toy example follows:
a <- matrix(1:30,5,6)
jj <- list(5:1,6:1)
I want the following
a[ jj[[1]],jj[[2]] ]
How do I do this?
OBAttempts:
2006 Nov 17
2
do.call("+", ...)
Hi
How do I make do.call() take "+" as a function for a list of more
than two elements?
Toy problem follows:
f <- function(i){matrix((1:6)^i,2,3)}
# Thus f() returns a matrix of size 2x3; I want to add a whole bunch
of such matrices,
# as in f(1) + f(2) + f(3) + f(4)
# But:
> do.call("+",sapply(1:4,f,simplify=FALSE))
Error in do.call("+",
2005 Apr 21
1
colSums and rowSums with arrays - different classes and dim ?
Hi,
I'm using colSums and rowSums to sum the first dimensions of arrays. It
works ok but the resulting object is different. See
> a3d <- array(rnorm(120, mean=2), dim=c(20,6,1))
> dim(colSums(a3d))
[1] 6 1
> dim(rowSums(a3d))
NULL
> class(colSums(a3d))
[1] "matrix"
> class(rowSums(a3d))
[1] "numeric"
I was expecting rowSums to preserve the array
2009 Nov 30
2
command similar to colSums for rowSums?
Working with an NxMxO sized matrix, currently I can do this in my code:
if (max(colSums(array)) >= number)
But to get an equivalent result using rowSums, I have to do:
for (i in 1:10)
{
if (max(rowSums(array[,,i])) >= number)
}
I'm running both in a much larger loop that loops millions of times, so
speed and such is quite a big factor for me. Currently, the colSums line
uses about
2011 May 16
2
conditional rowsums in sapply
Hi all
I have a data frame with duplicate columns and i want to remove duplicates
by adding rows in each group of duplicates, but have lots of NA's.
Data:
dfrm <- data.frame(a = 1:4, b= 1:4, cc= 1:4, dd=1:10, ee=1:4)
names(dfrm) <- c("a", "a", "b", "b", "b")
dfrm[3,2:3]<-NA
dfrm
a a b b b
1 1 1 1 1 1
2 2 2 2 2 2
3
2010 Nov 18
2
RowSums Question
I have a question on RowSums.
Lets say i have a timeSeries table
A B C
1/1/90 NA 1 1
1/2/90 NA 1 1
1/3/90 NA 1 1
1/4/90 NA 1 1
1/5/90 1 1 1
1/6/90 1 1 1
if i use RowSums, i will get
1/5/90 3
1/6/90 3
but i want
1/1/90 2
1/2/90 2
1/3/90 2
1/4/90 2
1/5/90 3
1/6/90 3
I cant
2008 Jan 07
2
S3 vs S4 for a simple package
I am writing a package and need to decide whether to use S3 or S4.
I have a single class, "multipol"; this needs methods for "[" and "[<-"
and I also need a print (or show) method and methods for arithmetic +-
*/^.
In S4, an object of class "multipol" has one slot that holds an array.
Objects of class "multipol" require specific arithmetic
2008 Jan 11
2
How to add rowSums into list?
Hi R-users,
I have a list
a <- list(one=matrix(rnorm(20), 5, 4), two=matrix(rnorm(20, 3, 0.5),5,4))
How to add rowSums (calculated using lapply) to corresponding matrix
in this list
lapply(a, function(x) rowSums(x))
??
-Lauri
2008 Sep 24
4
rowSums()
Say I have the following data:
testDat <- data.frame(A = c(1,NA,3), B = c(NA, NA, 3))
> testDat
A B
1 1 NA
2 NA NA
3 3 3
rowsums() with na.rm=TRUE generates the following, which is not desired:
> rowSums(testDat[, c('A', 'B')], na.rm=T)
[1] 1 0 6
rowsums() with na.rm=F generates the following, which is also not
desired:
> rowSums(testDat[, c('A',
2006 Nov 21
2
using nested ifelse and rowSums to create new variable?
Dear R-help community,
If I have a data.frame df as follows:
> df
x1 x2 x3 x4 x5 x6
1 5 5 1 1 2 1
2 5 5 5 5 1 5
3 1 5 5 5 5 5
4 5 5 1 4 5 5
5 5 1 5 2 4 1
6 5 1 5 4 5 1
7 5 1 5 4 4 5
8 5 1 1 1 1 5
9 1 5 1 1 2 5
10 5 1 5 4 5 5
11 1 5 5 2 1 1
12 5 5 5 4 4 1
13 1 5 1 4 4 1
14 1 1 5 4 5 5
15 1 5 5 4
2010 Dec 02
1
Arrange elements on a matrix according to rowSums + short 'apply' Q
Greetings,
My goal is to create a Markov transition matrix (probability of moving from
one state to another) with the 'highest traffic' portion of the matrix
occupying the top-left section. Consider the following sample:
inputData <- c(
c(5, 3, 1, 6, 7),
c(9, 7, 3, 10, 11),
c(1, 2, 3, 4, 5),
c(2, 4, 6, 8, 10),
c(9, 5, 2, 1, 1)
)
MAT <- matrix(inputData,
2010 Aug 12
3
Error in rowSums
Hi
I am trying to calculate the row sums of a matrix i have created
The matrix ( FeaturePresenceMatrix) has been created by
1) Read csv
2) Removing unnecesarry data using [-1:4,] command
3) replacing all the NA values with as.numeric(0) and all others with as.numeric
(1)
When I carry out the command
TotalFeature <- rowrowSums(FeaturePresenceMatrix, na.rm = TRUE)
I get the following
2004 May 25
2
vectorize an expression
Hi guys. Another thing I cannot vectorize:
I have an array "a", of size 5-by-2, for example, of 5 2D vectors. I
also have a distance function that computes the distance between two
vectors (usual Euclidean distance is a good example but I have other metrics I
want to use as well). I want a 5-by-5 array with the [i,j]th element being
the distance from a[i,] to a[j,]
To Wit:
a
2012 Jun 05
3
rowSums problem
I'm having a very frustrating problem, trying to find the inverse distance
squared weighted interpolants of some weather data.
I have a data frame of weights, which sum to 1. I have attached the weights
data. I also have a data frame of temperatures at 48 grid points, which I
have also attached.
Now, all I need to do is multiply all of the rows of the temperature data
frame by the weights
2011 Nov 21
4
Discarding a matrix based on the rowSums value
Hello
I would appreciate your help on the followig. I want to generate random
binary matrices but I need to discard those with all-1 rows. That is, for a
10x10 matrix with five 1's
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 0 0 0 0 0 0 0 0 0 1
[2,] 0 0 0 0 0 0 1 0 0 0
[3,] 0 0 0 0 0 0 1
2005 Mar 08
2
a==0 vs as.integer(a)==0 vs all.equal(a,0)
hi
?integer says:
Note that on almost all implementations of R the range of
representable integers is restricted to about +/-2*10^9: 'double's
can hold much larger integers exactly.
I am getting very confused as to when to use integers and when not to.
In my line
I need exact comparisons of large integer-valued arrays, so I often use
as.integer(),
but the above
2010 Aug 13
2
Fw: Error in rowSums REPOST
For the query below I have also included the follwing information. Thanks for
your replies
> str(FeaturePresenceMatrix)
chr [1:65530, 1:40] "0" "0" "0" "0" "1" "0" "0" "0" "0" ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:65530] "4" "5" "6" "7" ...
2005 Nov 10
2
error in rowSums:'x' must be numeric
Dear All,
It's Eszter again from Hungary. I could not solve my problem form
yesterday, so I still have to ask your help.
I have a binary dataset of vegetation samples and species as a comma
separated file. I would like to calculate the Jaccard distance of the
dataset. I have the following error message:
Error in rowSums(x, prod(dn), p, na.rm) : 'x' must be numeric
In addition: