m all to a common type (often character), so it may give
you the wrong result in addition to being unnecessarily slow.
Bill Dunlap
TIBCO Software
wdunlap tibco.com
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf
Of Duncan Murdoch
Sent: Sunda
On 2014-03-17 01:31, Jeff Newmiller wrote:
Did you really intend to make all of the x values the same?
Not at all; the code in the loop was in fact just nonsense. The point
was to illustrate the huge difference in execution time. And that the
relative difference seems to increase fast with th
On 2014-03-16 23:56, Duncan Murdoch wrote:
On 14-03-16 2:57 PM, Göran Broström wrote:
I have always known that "matrices are faster than data frames", for
instance this function:
dumkoll <- function(n = 1000, df = TRUE){
dfr <- data.frame(x = rnorm(n), y = rnorm(n))
if (df){
Did you really intend to make all of the x values the same? If so, try one line
instead of the for loop:
dfr$x[ 2:n ] <- dfr$x[ 1 ]
If that was merely an error in your example, then you could use a different
one-liner:
dfr$x[ 2:n ] <- dfr$x[ seq.int( n-1 ) ]
In either case, the speedup is con
wdunlap tibco.com
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf
> Of Duncan Murdoch
> Sent: Sunday, March 16, 2014 3:56 PM
> To: Göran Broström; r-help@r-project.org
> Subject: Re: [R] data frame v
On 14-03-16 2:57 PM, Göran Broström wrote:
I have always known that "matrices are faster than data frames", for
instance this function:
dumkoll <- function(n = 1000, df = TRUE){
dfr <- data.frame(x = rnorm(n), y = rnorm(n))
if (df){
for (i in 2:NROW(dfr)){
if
Hello,
This is to be expected. Matrices can hold only one type of data so the
problem is solved once and for all, data frames can have many types of
data so the code to handle them must determine which type to handle on
every access.
Hope this helps,
Rui Barradas
Em 16-03-2014 18:57, Göran
I have always known that "matrices are faster than data frames", for
instance this function:
dumkoll <- function(n = 1000, df = TRUE){
dfr <- data.frame(x = rnorm(n), y = rnorm(n))
if (df){
for (i in 2:NROW(dfr)){
if (!(i %% 100)) cat("i = ", i, "\n")
dfr
On May 1, 2012, at 1:33 PM, Bert Gunter wrote:
AdvisoRs:
Is the following a bug, feature, hinky error message, or dumb Bert?
mtest <- matrix(1:12,nr=4)
dftest <- data.frame(mtest)
ix <- cbind(1:2,2:3)
mtest[ix] <- NA
mtest
[,1] [,2] [,3]
[1,]1 NA9
[2,]26 NA
[3,]3
Hello,
Bert Gunter wrote
>
> Duncan:
>
> Maybe there **is** a bug, then.
>
> > zmat <- matrix(1:12,nr=4)
>> zdf <- data.frame(zmat)
>> ix <- cbind(c(FALSE,TRUE),c(TRUE,TRUE))
>> zmat[ix]
> [1] 2 3 4 6 7 8 10 11 12
>> zdf[ix]
> [1] 2 3 4 6 7 8 10 11 12
>> zmat[ix] <- NA
>> zmat
>
P.S.
The way the logical matrix is constructed is NOT general purpose.
Quoting myself quoting Bert,
>
> Actually, it works, as long as the logical index matrix has the same
> dimensions as the data frame.
>
> zmat <- matrix(1:12,nr=4)
> zdf <- data.frame(zmat)
>
> # Numeric index matrix.
> ix <-
nd Data Analysis Division
Olympia, WA 98504-5204
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
project.org] On Behalf Of Bert Gunter
Sent: Tuesday, May 01, 2012 11:46 AM
To: Duncan Murdoch
Cc: r-help@r-project.org
Subject: Re: [R] Data frame vs matrix q
lympia, WA 98504-5204
>
>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
>> project.org] On Behalf Of Bert Gunter
>> Sent: Tuesday, May 01, 2012 11:46 AM
>> To: Duncan Murdoch
>> Cc: r-help@r-project.org
&
Research and Data Analysis Division
Olympia, WA 98504-5204
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Bert Gunter
> Sent: Tuesday, May 01, 2012 11:46 AM
> To: Duncan Murdoch
> Cc: r-help@r-project.org
&g
On 01/05/2012 2:45 PM, Bert Gunter wrote:
Duncan:
Maybe there **is** a bug, then.
> zmat<- matrix(1:12,nr=4)
> zdf<- data.frame(zmat)
> ix<- cbind(c(FALSE,TRUE),c(TRUE,TRUE))
> zmat[ix]
[1] 2 3 4 6 7 8 10 11 12
> zdf[ix]
[1] 2 3 4 6 7 8 10 11 12
> zmat[ix]<- NA
> zmat
nal Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Bert Gunter
> Sent: Tuesday, May 01, 2012 1:46 PM
> To: Duncan Murdoch
> Cc: r-help@r-project.org
> Subject: Re: [R] Data frame vs matrix quirk: Hinky error message?
Duncan:
Maybe there **is** a bug, then.
> zmat <- matrix(1:12,nr=4)
> zdf <- data.frame(zmat)
> ix <- cbind(c(FALSE,TRUE),c(TRUE,TRUE))
> zmat[ix]
[1] 2 3 4 6 7 8 10 11 12
> zdf[ix]
[1] 2 3 4 6 7 8 10 11 12
> zmat[ix] <- NA
> zmat
[,1] [,2] [,3]
[1,]159
[2,] NA N
On 01/05/2012 2:12 PM, Bert Gunter wrote:
Many thanks, Ista:
I only looked in "].default" so the answer is: Alternative 4: dumb
Bert. Rap knuckles with ruler.
Actually, indexing by a logical matrix doesn't make much sense to me
in either case, as it does not have the effect of selecting indivi
Many thanks, Ista:
I only looked in "].default" so the answer is: Alternative 4: dumb
Bert. Rap knuckles with ruler.
Actually, indexing by a logical matrix doesn't make much sense to me
in either case, as it does not have the effect of selecting individual
elements, which is what numeric matrix
On 01-May-2012 17:33:23 Bert Gunter wrote:
> AdvisoRs:
>
> Is the following a bug, feature, hinky error message, or dumb Bert?
>
> mtest <- matrix(1:12,nr=4)
> dftest <- data.frame(mtest)
> ix <- cbind(1:2,2:3)
> mtest[ix] <- NA
> mtest
> [,1] [,2] [,3]
> [1,]1 NA9
> [2,]
Hi Bert,
The failure itself is the documented behavior: ?'[.data.frame' says
"Matrix indexing ('x[i]' with a logical or a 2-column integer
matrix 'i') using '[' is not recommended, and barely supported.
For extraction, 'x' is first coerced to a matrix. For
replacement, a logical m
AdvisoRs:
Is the following a bug, feature, hinky error message, or dumb Bert?
> mtest <- matrix(1:12,nr=4)
> dftest <- data.frame(mtest)
> ix <- cbind(1:2,2:3)
> mtest[ix] <- NA
> mtest
[,1] [,2] [,3]
[1,]1 NA9
[2,]26 NA
[3,]37 11
[4,]48 12
## But ...
22 matches
Mail list logo