r

R: Error in FUN(X[[i]], …) : only defined on a data frame with all numeric variables

邮差的信 提交于 2021-02-11 08:22:08
问题 I am working with the R programming language. I am trying to plot some categorical and continuous data that I am working with, but I am getting an error that tells me that such plots are only possible with "only numeric variables". library(survival) library(ggplot2) data(lung) data = lung data$sex = as.factor(data$sex) data$status = as.factor(data$status) data$ph.ecog = as.factor(data$ph.ecog) str(data) #plot mycolours <- rainbow(length(unique(data$sex)), end = 0.6) # png("gally.png", 500,

R: Error in FUN(X[[i]], …) : only defined on a data frame with all numeric variables

微笑、不失礼 提交于 2021-02-11 08:19:42
问题 I am working with the R programming language. I am trying to plot some categorical and continuous data that I am working with, but I am getting an error that tells me that such plots are only possible with "only numeric variables". library(survival) library(ggplot2) data(lung) data = lung data$sex = as.factor(data$sex) data$status = as.factor(data$status) data$ph.ecog = as.factor(data$ph.ecog) str(data) #plot mycolours <- rainbow(length(unique(data$sex)), end = 0.6) # png("gally.png", 500,

A warning which doesn't show up in the R CMD check results: 1 warning or 0 warnings?

跟風遠走 提交于 2021-02-11 08:16:32
问题 I'm building an R package under Windows 10 with RStudio 1.0.136 and get a warning about qpdf (see How to build qpdf on Windows? for more details about this issue). But and the end of the checks, the number of warnings is shown to be 0. So I wonder if there is one or no warning that has to be solved before I can submit the package to CRAN? Here is the last part of the checks: ... checking for unstated dependencies in examples ... OK WARNING 'qpdf' is needed for checks on size reduction of PDFs

Error when trying to store list in data.table of length 1

和自甴很熟 提交于 2021-02-11 08:13:40
问题 When trying to store a vector in a data.table, this works only when the data.table has length of more than one. Please find below a simplified version of the problem library(data.table) Working fine dt <- data.table( a = c("a", "b"), l = list()) dt$l[[1]] <- c(1:3) Results in: a l 1: a 1,2,3 2: b Producing Error dt <- data.table( a = c("a"), l = list()) dt$l[[1]] <- c(1:3) Error in [<-.data.table(x, j = name, value = value) : Supplied 3 items to be assigned to 1 items of column 'l'. The RHS

A warning which doesn't show up in the R CMD check results: 1 warning or 0 warnings?

对着背影说爱祢 提交于 2021-02-11 08:11:18
问题 I'm building an R package under Windows 10 with RStudio 1.0.136 and get a warning about qpdf (see How to build qpdf on Windows? for more details about this issue). But and the end of the checks, the number of warnings is shown to be 0. So I wonder if there is one or no warning that has to be solved before I can submit the package to CRAN? Here is the last part of the checks: ... checking for unstated dependencies in examples ... OK WARNING 'qpdf' is needed for checks on size reduction of PDFs

Comparison loop

a 夏天 提交于 2021-02-11 08:10:04
问题 I have a nested list combine <- list(c('A', 'B', 'C'), c('D', 'H', 'G', 'J'), c('A', 'E')) and a df df <- data.frame(appln_id = c(1, 1, 2, 2, 4, 4, 4, 3, 3, 3, 3, 5, 9, 9), prior_year = c(1997,1997,1997,1997,1997,1997,1997,1998,1998,1998,1998,2000,2000,2000), IPC = c('B','E','E','B','H','J','D','H','J','D','E','A','E','B')) I want to aggregate IPC according to appln_id (eg: for appln_id=1: c('B','E') , for appln_id=2: c('E','B') , for appln_id=4: c('H','J','D') , etc.). Then for each value of

Comparison loop

别来无恙 提交于 2021-02-11 08:09:04
问题 I have a nested list combine <- list(c('A', 'B', 'C'), c('D', 'H', 'G', 'J'), c('A', 'E')) and a df df <- data.frame(appln_id = c(1, 1, 2, 2, 4, 4, 4, 3, 3, 3, 3, 5, 9, 9), prior_year = c(1997,1997,1997,1997,1997,1997,1997,1998,1998,1998,1998,2000,2000,2000), IPC = c('B','E','E','B','H','J','D','H','J','D','E','A','E','B')) I want to aggregate IPC according to appln_id (eg: for appln_id=1: c('B','E') , for appln_id=2: c('E','B') , for appln_id=4: c('H','J','D') , etc.). Then for each value of

Remove prefix letter from column variables

女生的网名这么多〃 提交于 2021-02-11 07:53:31
问题 I have all column names that start with ' m '. Example: mIncome, mAge . I want to remove the prefix . So far, I have tried the following: df %>% rename_all(~stringr::str_replace_all(.,"m","")) This removes all the column names that has the letter ' m '. I just need it removed from from the start. Any suggestions? 回答1: We need to specify the location. The ^ matches the start of the string (or here the column name). So, if we use ^m , it will only match 'm' at the beginning or start of the

Multiple Pivot Table - R (table)

南笙酒味 提交于 2021-02-11 07:46:33
问题 I have the following: Type State A California B Washington A California A California A Washington B New York I would like to do a pivot in R to find out the number of each type in each state. I have figured out how to find out the number of each type (without state breakdown) by using: table(df$Type) This gives me the following result: Var1 Freq A 4 B 2 However, I would like to add a second dimension such that I can get a state breakdown of the above result. A suggested output would look like

Multiple Pivot Table - R (table)

和自甴很熟 提交于 2021-02-11 07:46:12
问题 I have the following: Type State A California B Washington A California A California A Washington B New York I would like to do a pivot in R to find out the number of each type in each state. I have figured out how to find out the number of each type (without state breakdown) by using: table(df$Type) This gives me the following result: Var1 Freq A 4 B 2 However, I would like to add a second dimension such that I can get a state breakdown of the above result. A suggested output would look like