r

splitting list into its components and combine to form another list in R [duplicate]

时光怂恿深爱的人放手 提交于 2021-02-11 16:47:50
问题 This question already has answers here : How to combine two lists in R (3 answers) Closed 12 months ago . I have list 1: l1 <- list(letters[1:26]) I have list 2: l2 <- list(c(1:26)) How would I combine l1 and l2 into a new list l4 with 52 elements: the first 26 elements are the elements of l1 and the next 26 are the elements of l2 ? 回答1: You could use c to combine them l4 <- c(l1[[1]], l2[[1]]) Or with unlist l4 <- c(unlist(l1), unlist(l2)) Maybe you want to wrap it in list l4 <- list(c(l1[[1

R - Defining a function which recognises arguments not as objects, but as being part of the call

会有一股神秘感。 提交于 2021-02-11 16:46:16
问题 I'm trying to define a function which returns a graphical object in R. The idea is that I can then call this function with different arguments multiple times using an for loop or lapply function, then plotting the list of grobs in gridExtra::grid.arrange . However, I did not get that far yet. I'm having trouble with r recognising the arguments as being part of the call. I've made some code to show you my problem. I have tried quoting and unquoting the arguments, using unqoute() in the

Error during wrapup: long vectors not supported yet: in glm() function

倾然丶 夕夏残阳落幕 提交于 2021-02-11 16:42:44
问题 I found several questions on Stackoverflow regarding this topic (some of them without any answer) but nothing related (so far) with this error in regression. I'm, running a probit model in r with (I'm guessing) too many fixed effects (year and places): myprobit <- glm(factor(Y) ~ factor(T) + factor(X1) + factor(X2) + factor(X3) + factor(YEAR) + factor(PLACE), family = binomial(link = "probit"), data = DT) The PLACE variable has about 1000 unique values and YEAR 8 values. The dataset DT has 13

variable use in dplyr and ggplot

喜你入骨 提交于 2021-02-11 16:38:35
问题 I'm trying to sort out functional programming with dplyr/ggplot. In my first couple of weeks of R I mostly went by trial and error following snippets found on the web, but I'm trying to understand this better so it comes more natural. I'm playing around with mtcars as an example: library(tidyverse) data <- mtcars data$carb <- as.factor(data$carb) My sample code w/o using variables looks like this: data %>% filter(carb != 4) %>% ggplot() + geom_point(aes(x = mpg, y = hp, color = carb)) +

variable use in dplyr and ggplot

拜拜、爱过 提交于 2021-02-11 16:37:54
问题 I'm trying to sort out functional programming with dplyr/ggplot. In my first couple of weeks of R I mostly went by trial and error following snippets found on the web, but I'm trying to understand this better so it comes more natural. I'm playing around with mtcars as an example: library(tidyverse) data <- mtcars data$carb <- as.factor(data$carb) My sample code w/o using variables looks like this: data %>% filter(carb != 4) %>% ggplot() + geom_point(aes(x = mpg, y = hp, color = carb)) +

R Aggregate over multiple columns

非 Y 不嫁゛ 提交于 2021-02-11 16:36:56
问题 i´m currently working with a large dataframe of 75 columns and round about 9500 rows. This dataframe contains observations for every day from 1995-2019 for several observation points. Edit: The print from dput(head(df)) > dput(head(df)) structure(list(date = structure(c(9131, 9132, 9133, 9134, 9135, 9136), class = "Date"), x1 = c(50.75, 62.625, 57.25, 56.571, 36.75, 39.125), x2 = c(62.25, 58.714, 49.875, 56.375, 43.25, 41.625), x3 = c(90.25, NA, 70.125, 75.75, 83.286, 98.5), x4 = c(60, 72, 68

variable use in dplyr and ggplot

大憨熊 提交于 2021-02-11 16:36:53
问题 I'm trying to sort out functional programming with dplyr/ggplot. In my first couple of weeks of R I mostly went by trial and error following snippets found on the web, but I'm trying to understand this better so it comes more natural. I'm playing around with mtcars as an example: library(tidyverse) data <- mtcars data$carb <- as.factor(data$carb) My sample code w/o using variables looks like this: data %>% filter(carb != 4) %>% ggplot() + geom_point(aes(x = mpg, y = hp, color = carb)) +

R Aggregate over multiple columns

◇◆丶佛笑我妖孽 提交于 2021-02-11 16:36:50
问题 i´m currently working with a large dataframe of 75 columns and round about 9500 rows. This dataframe contains observations for every day from 1995-2019 for several observation points. Edit: The print from dput(head(df)) > dput(head(df)) structure(list(date = structure(c(9131, 9132, 9133, 9134, 9135, 9136), class = "Date"), x1 = c(50.75, 62.625, 57.25, 56.571, 36.75, 39.125), x2 = c(62.25, 58.714, 49.875, 56.375, 43.25, 41.625), x3 = c(90.25, NA, 70.125, 75.75, 83.286, 98.5), x4 = c(60, 72, 68

What is the simplest way to control the y-axis when using sec.axis

自闭症网瘾萝莉.ら 提交于 2021-02-11 16:27:02
问题 I have reading all post about scaling the y-axis and in all of them there are some extra steps in order to control the y-axis limits when using sec.axis in ggplot. I have the following df. structure(list(day = c(1, 3, 5, 7, 9), mean = c(0.000452620431539136, 0.000244953967091816, 0.000409529176828165, 0.000621566432113383, 0.000975471413145951), sd = c(0.000145928952108396, 7.48403498938327e-05, 8.70694523628839e-05, 0.000265199022927143, 0.00076194983870935 ), group = c("pi", "pi", "pi", "pi

Constraints for nls coefficients

孤人 提交于 2021-02-11 15:57:47
问题 I'm trying to fit data with nls() function where the nature of data gives me bounds for one coefficient and for sum of two coefficients. Let me introduce short example to see where is the problem. I want parameter b1 to be between 0 and 1 and I want sum of parameters b1 and b2 to be between 0 and 1 as well. set.seed(123) # example where everything is OK x <- 1:200 g <- rbinom(200, 1, 0.5) y <- 3 + (0.7 + 0.2 * g) * x yeps <- y + rnorm(length(y), sd = 0.1) # both parameter b1 and sum of