Displaying 20 results from an estimated 10000 matches similar to: "is.null(mylist[1]) and is.null(mylist$a) returns different values"
2017 Jun 15
0
is.null(mylist[1]) and is.null(mylist$a) returns different values
Hi,
Try
> is.null(mylist[[1]])
[1] TRUE
Notice the double square brackets.
From: ?`[`
"The most important distinction between [, [[ and $ is that the [ can
select more than one element whereas the other two select a single
element."
On Thu, Jun 15, 2017 at 11:33 AM, ce <zadig_1 at excite.com> wrote:
> Hi
>
> I have a list :
>
> mylist <- list( a = NULL, b
2017 Jun 15
1
is.null(mylist[1]) and is.null(mylist$a) returns different values
I find that the str function is more helpful for understanding the difference between a null list and a list containing a null list than the implicit print function call that the interpreter invokes when you enter an expression at the console.
str( mylist[1] )
--
Sent from my phone. Please excuse my brevity.
On June 15, 2017 8:39:47 AM PDT, Huzefa Khalil <huzefa.khalil at umich.edu>
2017 Jun 15
0
is.null(mylist[1]) and is.null(mylist$a) returns different values
Thank you all , very informative, never thought of doing a str( mylist[1] )
-----Original Message-----
From: "Jeff Newmiller" [jdnewmil at dcn.davis.ca.us]
Date: 06/15/2017 11:56 AM
To: r-help at r-project.org, "Huzefa Khalil" <huzefa.khalil at umich.edu>, "ce" <zadig_1 at excite.com>
Subject: Re: [R] is.null(mylist[1]) and is.null(mylist$a) returns
2018 May 08
3
Bilateral matrix
or in base R : ?xtabs ??
as in:
xtabs(~previous_location + current_location,data=x)
(You can convert the 0s to NA's if you like)
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Tue, May 8, 2018 at 9:21 AM, Huzefa
2018 May 16
0
Bilateral matrix
Dear Bert and Huzefa,
Apologies for the late reply, my account got hacked and I have just managed
to recover it.
Thank you very much for your replies and the solutions. Both work well.
I was wondering if there was any way to ensure (force) that all possible
combinations show up in the output. The full dataset has 25 cities but of
course people have not moved from Boston to all the other 24
2016 Apr 12
0
ggplot2
Hi James,
If you want to specify the y-values, you need to use stat="identity" as below:
ggplot(probability, aes(x=Fertilizer, y=prob)) +
geom_bar(stat="identity", aes(fill=Treatment))
best,
huzefa
On Tue, Apr 12, 2016 at 1:02 PM, James Henson <jfhenson1 at gmail.com> wrote:
> Dear R Community,
>
> Below is a problem with a simple ggplot2 graph. The code
2016 Apr 12
2
ggplot2
Dear R Community,
Below is a problem with a simple ggplot2 graph. The code returns the error
message below.
Error: stat_count() must not be used with a y aesthetic.
My code is below and the data is attached as a ?text? file.
# Graph of the probabilities
library(digest)
library(DT)
datatable(probability)
str(probability)
probability$Fertilizer <- as.factor(probability$Fertilizer)
2018 May 04
0
Converting a list to a data frame
It looks like you made a copy/paste error below. Your ata.frame should
be data.frame.
Kevin
On 05/04/2018 08:18 AM, Bill Poling wrote:
> Good morning.
>
> Novice usR. Here.
>
> I am following this string, among many, learning as I go.
>
> Quick question please?
>
> I thought that perhaps ata.frame was part of the zoo pkg, b/c when I
> searched it came up in
2018 May 04
2
Converting a list to a data frame
Good morning.
Novice usR. Here.
I am following this string, among many, learning as I go.
Quick question please?
I thought that perhaps ata.frame was part of the zoo pkg, b/c when I searched it came up in help?
However, evidently not or I am not using it properly.
Please advise, thank you.
x <- list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8))
x2 <- do.call(rbind,
2018 May 16
2
Bilateral matrix
xtabs does this automatically if your cross classifying variables are
factors with levels all the cities (sorted, if you like):
> x <- sample(letters[1:5],8, rep=TRUE)
> y <- sample(letters[1:5],8,rep=TRUE)
> xtabs(~ x + y)
y
x c d e
a 1 0 0
b 0 0 1
c 1 0 0
d 1 1 1
e 1 1 0
> lvls <- sort(union(x,y))
> x <- factor(x, levels = lvls)
> y <-
2018 May 15
0
Forecasting tutorial "Basic Forecasting"
Instead of
Tsp = c(2016, 2018, 12)
try
Tsp = c(2016, 2018.25, 12)
Hence, you can specify the object as
structure(c(5973156.76, 5159011.2, 6695766.64, 6365359, 6495218.53,
7226302.39, 6835272.7, 7383501.57, 6962748.19, 7623278.72, 7274994.33,
7919421.8, 7360740.81, 7436693.35, 8545765.55, 7337269.76, 8180585.44,
8376635.05, 7758261.24, 10374641.22, 8000314.11, 9114958.9, 9805149.15,
2018 May 15
3
Forecasting tutorial "Basic Forecasting"
Hi. I am trying to follow this forecasting tutorial at: https://www.r-bloggers.com/basic-forecasting/
Using my own data, I cannot get past the first step, lots of laughs.
dat3 <- structure(c(5973156.76, 5159011.20, 6695766.64, 6365359.00, 6495218.53, 7226302.39, 6835272.70, 7383501.57, 6962748.19, 7623278.72, 7274994.33
,7919421.80, 7360740.81, 7436693.35,
2009 Oct 25
3
NULL elements in lists ... a nightmare
I can define a list containing NULL elements:
> myList <- list("aaa",NULL,TRUE)
> names(myList) <- c("first","second","third")
> myList
$first
[1] "aaa"
$second
NULL
$third
[1] TRUE
> length(myList)
[1] 3
However, if I assign NULL to any of the list element then such
element is deleted from the list:
> myList$second <-
2018 May 08
0
Bilateral matrix
Dear Miluji,
If I understand correctly, this should get you what you need.
temp1 <-
structure(list(id = 101:115, current_location = structure(c(2L,
8L, 8L, 3L, 6L, 5L, 1L, 2L, 7L, 4L, 2L, 8L, 8L, 3L, 6L), .Label =
c("Austin",
"Boston", "Cambridge", "Durham", "Houston", "Lynn", "New Orleans",
"New York"), class =
2018 May 17
0
Bilateral matrix
Dear William and Ben,
Thank you for your replies and elegant solutions. I am having trouble with
the fact that two of the previous locations do not appear in current
locations (that is no one moved to OKC and Dallas from other cities), so
these two cities are not being included in the output.
I have provided a better sample of the data and the ideal output (wide form
- a 10x10 bilateral matrix)
2018 May 08
2
Bilateral matrix
I have data on current and previous location of individuals. I would like
to have a matrix with bilateral movement between locations. I would like
the final output to look like the second table below.
I have tried using crosstab() from the ecodist but I do not have another
variable to measure the flow. Ultimately I would like to compute the
probability of movement between cities (movement to
2017 Aug 14
0
Help creating the IBM Randu function
Hi Martin,
The corrected function would be
RANDU <- function(num) { return ((65539*num)%%(2^31)) }
You forgot the brackets for the return function.
Hence, what was returned was always (65539 * num)
On Mon, Aug 14, 2017 at 12:49 PM, Martin M?ller Skarbiniks Pedersen
<traxplayer at gmail.com> wrote:
> Dear all,
>
> I am trying to learn functions in R and 3D plotting so I
2017 Aug 14
4
Help creating the IBM Randu function
Dear all,
I am trying to learn functions in R and 3D plotting so I decided to try
to plot
the famous bad PRNG Randu from IBM(1).
However something is not correct in the function I have created.
First I define the function RANDU like this:
> RANDU <- function(num) { return (65539*num)%%(2^31) }
and test that it works for a seed of 1:
> RANDU(1)
[1] 65539
but if I want the next
2013 Jun 16
4
can't install rugarch and nloptr packages in R 3.01 opensuse linux
I can't install rugarch package because installation of nloptr package fails .
I use opensuse 12.3
# uname -a
Linux candide 3.7.10-1.11-desktop #1 SMP PREEMPT Thu May 16 20:27:27 UTC 2013 (adf31bb) x86_64 x86_64 x86_64 GNU/Linux
my gcc version is 4.8.1
I compiled and installed R 3.01 . then I tried to install rugarch package but it fails because it can't install depended package nloptr.
2018 May 02
0
Converting a list to a data frame
Hi Kevin,
There is probably a better way, but it can be done in two steps like this
temp <- list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8))
temp <- lapply(names(temp), function(n, temp) {
temp[[n]]$type <- n
return(temp[[n]])
}, temp = temp)
do.call(rbind, temp)
On Wed, May 2, 2018 at 1:11 PM, Kevin E. Thorpe <kevin.thorpe at utoronto.ca>
wrote:
> I suspect