Hi Avi,
As Duncan already mentioned, a reproducible example would be helpful to
assist you better. Having said that, I think you misunderstand how
`dplyr::filter` works: it performs row-wise filtering, so the filtering
expression shall return a logical vector of the same length as the
y downside to it? Or is the side note
meant to tell me to drop the last: "%>% `[`"?
Thank you,
==
Michael Lachanski
PhD Student in Demography and Sociology
MA Candidate in Statistics
University of Pennsylvania
mikel...@sas.upenn.edu <mailto:mikel...@sas.upenn.edu>
On
Hi Michael,
Note that you have to be very careful when using by-reference operations
in data.table (see `?data.table::set`), especially in a functional
programming approach. In your function, you avoid this problem by
calling `data.table(A)` which makes a copy of A even if it is already a
Or if your data is really large, you can try data.table::dcast().
> library(data.table)
> dcast(ID ~ station, data = as.data.table(df1))
ID xy xz
1: 12 15 20
2: 13 16 19
(Note: instead of `as.data.table()`, you can use `setDT` or create your
object as a data.table in the first place.)
On
Hi Tim,
I have also asked a similar question a couple of months ago, and someone
else did the same recently, maybe on r-devel.
We received no "official" response, but Deepayan Sarkar (R Core Team
member) claimed that:
"
There is no documented reason for this to work (AFAIK), so again, I
On 3/18/20 9:02 PM, Bert Gunter wrote:
Untested in the absence of example data, but I think
combined <- do.call(rbind, lapply(ls2972, function(x)get(x)[[2]]))
Or if you have largish data, use rbindlist() from the data.table package:
combined <- data.table::rbindlist(
lapply(ls2972,
Dear Martin,
Others struggle with this inconsistency as well; I found this discussion
useful:
https://math.stackexchange.com/questions/1098138/chi-square-or-chi-squared
Denes
On 10/18/19 2:51 PM, Martin Maechler wrote:
As it's Friday ..
and I also really want to clean up help files and
Hi Bert,
see inline.
On 7/30/19 1:12 AM, Bert Gunter wrote:
While Eric's solution is correct( mod "corner" cases like all NA's in
a row), it can be made considerably more efficient.
One minor improvement can be made by using the idiom
any(x == "A")
instead of matching via %in% for the simple
On 7/10/19 5:54 PM, Richard O'Keefe wrote:
Expectation: ifelse will use the same "repeat vectors to match the longest"
rule that other vectorised functions do. So
a <- 1:5
b <- c(2,3)
ifelse(a < 3, 1, b)
=> ifelse(T T F F F <<5>>, 1 <<1>>, 2 3 <<2>>)
=> ifelse(T T F F F <<5>>, 1 1 1 1 1
Hi Rebecca,
I think it was me how suggested you the missRanger package, so this is
actually a follow-up of you previous question about censored imputation
of missing values (as far as I can remember).
The missRanger package uses predictive mean matching, so take a look at
?missRanger::pmm
Hi,
The missRanger package performs predictive mean matching which should
generate positive values if the non-missing values are positive.
Regards,
Denes
On 11/09/2018 01:11 PM, Rebecca Bingert wrote:
Hi!
How can I generate only positive data with randomForrest-imputation? I'm
working
It works perfectly as I want!
Thanks a lot.
On Fri, Oct 12, 2018 at 6:29 AM Dénes Tóth
wrote:
On 10/12/2018 12:12 AM, roslinazairimah zakaria wrote:
Dear r-users,
I have this data:
structure(list(STUDENT_ID = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L), .Label = c("AA1
On 10/12/2018 12:12 AM, roslinazairimah zakaria wrote:
Dear r-users,
I have this data:
structure(list(STUDENT_ID = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L), .Label = c("AA15285", "AA15286"), class = "factor"),
COURSE_CODE = structure(c(1L, 2L, 5L, 6L, 7L, 8L, 2L, 3L,
Hi Luigi,
Actually I doubt that the original problem you try to solve requires the
initialization of an empty data.frame with a particular structure.
However, if you think you really need this step, I would write a
function for it and also consider edge cases.
getSkeleton <- function(x,
On 07/26/2018 08:58 PM, JEFFERY REICHMAN wrote:
Given something like ...
x <- c(3,2,4,3,5,4,3,2,4,5)
y <- c("A","B","B","A","A","A","A","B","A","B")
xy <- data.frame(x,y)
xy$w <- ifelse(xy$y=="A",xy$w[,x]*10,xy$w[,x]*15 )
You should learn the basics about how to extract or replace part of
On 07/25/2018 10:23 AM, Ivan Calandra wrote:
Just for my understanding:
Is a data.frame with list columns still a data.frame? Isn't it then a list?
A data.frame is a list of equally sized vectors - that is, each vector
must be of the same length. It is not required that the vector is an
Hi Martin,
I assume you want to check whether a particular character string
contains a digit. In this case you should use the following pattern:
"[[:digit:]]" instead of "[:digit:]".
From ?regex:
"A character class is a list of characters enclosed between [ and ]
which matches any single
You might find this discussion useful, too:
https://github.com/Rdatatable/data.table/issues/2797
On 04/26/2018 11:01 PM, Henrik Bengtsson wrote:
If you're installing packages to the default location in your home
account and you didn't remove those library folders, you still have
you R 3.4
Hi Juan,
you might find this useful: https://sourceforge.net/projects/rportable/
Cheers,
Denes
On 01/26/2018 11:57 AM, Juan Manuel Truppia wrote:
Pretty good question Gabor. I can execute R once it is installed (if
someone with rights installs it before) but not the installer. I can
download
Hi Harold,
Generally: you can not beat data.table, unless you can represent your
data in a matrix (or array or vector). For some specific cases, Hervé's
suggestion might be also competitive.
Your problem is that you did not put any effort to read at least part of
the very extensive
On 09/05/2016 12:07 AM, Bert Gunter wrote:
Time for an R tutorial or two to learn how to use the "apply" family
in R. I think what you want is:
merged_list <- lapply(merging, get)
Or even:
named_merged_list <- mget(merging)
Anyway, probably you could arrive to a list of parameters
On 07/17/2016 01:39 AM, Duncan Murdoch wrote:
On 16/07/2016 6:25 PM, Ashta wrote:
> Hi all,
>
> I have a large square matrix (60 x 60) and found it hard to
> visualize. Is it possible to change it as shown below?
>
> Sample example (3 x 3)
>
> A B C
> A 3 4 5
> B 4
On 06/15/2016 09:05 PM, peter dalgaard wrote:
>
>> On 15 Jun 2016, at 19:37 , Nick Tulli wrote:
>>
>> Hey R-Help,
>>
>> I've got a three dimensional array which I pulled from a netcdf file.
>> The data in array are the humidity values of locations in the United
>>
Hi Martin,
On 03/22/2016 10:20 AM, Martin Maechler wrote:
>>>>>Dénes Tóth<toth.de...@ttk.mta.hu>
>>>>> on Fri, 18 Mar 2016 22:56:23 +0100 writes:
> Hi Roy,
> R (usually) makes a copy if the dimensionality of an array is modified,
Hi Roy,
R (usually) makes a copy if the dimensionality of an array is modified,
even if you use this syntax:
x <- array(1:24, c(2, 3, 4))
dim(x) <- c(6, 4)
See also ?tracemem, ?data.table::address, ?pryr::address and other tools
to trace if an internal copy is done.
Workaround: use
Hi,
Although you did not provide any reproducible example, it seems you
store the same type of values in your data.frames. If this is true, it
is much more efficient to store your data in an array:
mylist <- list(a = data.frame(week1 = rnorm(24), week2 = rnorm(24)),
b =
On 02/05/2016 05:25 PM, Duncan Murdoch wrote:
On 05/02/2016 11:14 AM, Jinsong Zhao wrote:
Dear there,
Here is a snipped code,
> rm(list = ls())
> x <- 123
> save.image("abc.RData")
> rm(list = ls())
> load("abc.RData")
> sample(10)
[1] 3 7 4 6 10 2 5 9 8 1
> rm(list
Hi,
I have not followed this thread from the beginning, but have you tried
the foverlaps() function from the data.table package?
Something along the lines of:
---
# create the tables (use as.data.table() or setDT() if you
# start with a data.frame)
mapfile <- data.table(Name = c("S1", "S2",
Hi,
Provide a list of a list in the second assignment:
--
TunePar <- matrix(list(NULL), 2, 2)
TunePar[2,1] <- list(list(G = 2))
TunePar[2,1]
TunePar[2,1][[1]]$G
TunePar[[2]]$G
---
The point is that "[" returns the list element of the same level as the
original object (TunePar in the present
Hi,
Bill was faster than me in suggesting aperm() instead of apply(),
however, his solution is still suboptimal. Try to avoid array(), and
set the dimensions directly if possible.
fn1 <- function(x) {
apply(x, 3, t)
}
fn2 <- function(x) {
array(aperm(x, c(2, 1, 3)),
Hi,
the eegkit package
(https://cran.r-project.org/web/packages/eegkit/index.html) might help
you if you happen to work with a standard electrode cap.
Best,
Denes
On 10/19/2015 02:41 PM, Charles Novaes de Santana wrote:
Dear all,
I have .csv file with the evoked potential of different
Hi Matt,
you could use matrix indexing. Here is a possible solution, which could
be optimized further (probably).
# The old matrix
(old.mat <- matrix(1:30,nrow=3,byrow=TRUE))
# matrix of indices
index <- matrix(c(1,1,1,4,
1,3,5,10,
2,2,1,3,
On 09/16/2015 04:41 PM, Bert Gunter wrote:
Yes! Chuck's use of mapply is exactly the split/combine strategy I was
looking for. In retrospect, exactly how one should think about it.
Many thanks to all for a constructive discussion .
-- Bert
Bert Gunter
Use mapply like this on large
Hi,
Here is a solution which is restricted to lists with identically shaped
branches (like your example). The idea is to transform the list to an
array and make use of the fact that unlist(x, use.names=FALSE) is much
much faster for large lists than unlist(x).
# function which transforms a
Dear Jeff,
On 12/17/2014 01:46 AM, Jeff Newmiller wrote:
You are chasing ghosts of performance past, Denes.
In terms of memory efficiency, yes. In terms of CPU time, there can be
significant difference, see below.
The data.frame
function causes no problems, and if it is used then the OP
On 12/16/2014 06:06 PM, SH wrote:
Dear List,
I hope this posting is not redundant. I have several list outputs with the
same components. I ran a function with three different scenarios below
(e.g., scen1, scen2, and scen3,...,scenN). I would like to extract the
same components and group
Hi,
It is better to use sweep() for these kinds of problems, see ?sweep
y - matrix(cbind(c(0, 0.5, 1),c(0, 0.5, 1)),ncol=2)
z - matrix(c(12, -6),ncol=2)
sweep(y, 2, z, *)
Best,
Denes
On 11/19/2014 03:50 PM, Berend Hasselman wrote:
On 19-11-2014, at 15:22, Ruima E. ruimax...@gmail.com
Hi,
just for the records, your original code seems incorrect, see inline.
On 11/19/2014 03:22 PM, Ruima E. wrote:
Hi,
I have this:
y = matrix(cbind(c(0, 0.5, 1),c(0, 0.5, 1)),ncol=2)
z = matrix(c(12, -6),ncol=2)
In matlab I would do this
y .* x
Here you wrote 'x' which I guess refers to
Hi,
Dear R developers,
I want to draw an arrow in a figure with lty=2. The
lty argument also affects the edge of the arrow, which is
unfortunate. Feature or bug?
Is there some way to draw an arrow with intact edge, still
with lty=2?
AFAIK there is no such option in the arrow function,
On Oct 21, 2011, at 09:01 , Martin Maechler wrote:
ARE == Alex Ruiz Euler rruizeu...@ucsd.edu
on Wed, 19 Oct 2011 14:05:16 -0700 writes:
ARE Motion supported. Very.
ARE On Wed, 19 Oct 2011 15:40:14 +0200
ARE peter dalgaard pda...@gmail.com wrote:
Argh!
Someone please
Dear Ravi,
I would also suggest you to have a look at 'lavaan' (www.lavaan.org). It
has an extremely straightforward yet flexible model syntax and very good
documentation. Although its statistical capabilities are not comparable to
those of Mplus (which is the most powerful SEM-software I
If you want to generate truncated distributions, package 'tmvtnorm' can
help you out.
Regards,
Denes
Dear all,
I know there have been various questions posted over the years about
loops
but I'm afraid that I'm still stuck. I am using Windows XP and R 2.9.2.
I am generating some data
Hi,
One way to do that is this (avoiding the use of a for loop):
l.txt- id category attribute1 attribute2 attribute3 attribute4
661 SCHS 43.2 0 56.5 1
12202 SCHS 161.7 5.7 155 16
1182 SCHS 21.4 0 29 0
1356 SSS 8.8182 0.1818 10.6667 0.6667
1864 SCHS 443.7273 9.9091 537 46
12360 SOA
which.max is even faster:
dims - c(1000,1000)
tt - array(rnorm(prod(dims)),dims)
# which
system.time(
replicate(100, which(tt==max(tt), arr.ind=TRUE))
)
# which.max ( arrayInd)
system.time(
replicate(100, arrayInd(which.max(tt), dims))
)
Best,
Denes
But it's simpler and probably faster to use
And you might also consider packages like corrplot, corrgram etc. for
other plotting options of a correlation matrix.
They can be more informative than simply invoking image(heat)
What a pleasant post to respond to - with self-contained code. :)
Dear All:
I am calculating the relative importance of a regressor in a linear
model.
Does anyone know how I can obtain/install the 'pmvd' computation type? I
am
a US user.
Regards,
Y
Hi,
Do you have any specific reason to use the pmvd method, especially in
the light of
Dear Jen,
Actually you can check out what R does by looking at the source.
# first type the name of the function
rstandard
function (model, ...)
UseMethod(rstandard)
environment: namespace:stats
# ?methods will list you the corresponding functions
methods(rstandard)
[1] rstandard.glm
See also ?tabulate.
tabulate(x,8)
Hi Paul,
I would use something like this:
x - c(2,2,3,3,4,6)
table(x)
x
2 3 4 6
2 2 1 1
x - factor(x, levels=1:8)
table(x)
x
1 2 3 4 5 6 7 8
0 2 2 1 0 1 0 0
Sarah
On Sun, Jul 31, 2011 at 5:41 PM, Paul Menzel
Hi,
you can solve the task by simple matrix algebra.
Note that I find it really inconvenient to have a matrix with variables in
rows and cases in columns, so I transposed your predictors matrix.
# your data
regress.y = rnorm(150)
predictors = matrix(rnorm(6000*150), ncol=150, nrow=6000)
tpreds
The problem is that you can not assign a variable to itself.
rm(list=ls())
df1 - data.frame(ResultValue=as.character(1:5))
df2 - data.frame(ResultValue=as.character(1:10))
frames = ls()
for (frame in frames){
temp - get(frame)
temp[,ResultValue] = as.numeric(temp[,ResultValue])
Sorry, I was wrong. Of course you can assign a variable to itself, but it
does not make much sense...
What you misunderstood was that in the assignment you assign the data
frame (e.g. df1) to itself. You do not modify the frame object which
remains a character string.
The problem is that you
Hi,
you provided a character vector as an example. I guess you meant something
like:
x - factor(c(1,2,3,4,1))
# You can identify those elements with an by ?grep or ?grepl:
indices - grep(,as.character(x))
# You can transform those elements by ?as.numeric
as.numeric(x[indices])
HTH,
Denes
52 matches
Mail list logo