r

Replace NA when last and next non-NA values are equal

非 Y 不嫁゛ 提交于 2021-02-19 02:42:48
问题 I have a sample table with some but not all NA values that need to be replaced. > dat id message index 1 1 <NA> 1 2 1 foo 2 3 1 foo 3 4 1 <NA> 4 5 1 foo 5 6 1 <NA> 6 7 2 <NA> 1 8 2 baz 2 9 2 <NA> 3 10 2 baz 4 11 2 baz 5 12 2 baz 6 13 3 bar 1 14 3 <NA> 2 15 3 <NA> 3 16 3 bar 4 17 3 <NA> 5 18 3 bar 6 19 3 <NA> 7 20 3 qux 8 My objective is to replace the NA values that are surrounded by the same "message" using the first appearance of the message (the least index value) and the last appearance

r combine ggRadar and facet_wrap

久未见 提交于 2021-02-19 02:36:29
问题 The code below illustrates my question. I want to use the ggRadar function in ggiraphExtra because it allows interaction with the graph. I want a separate spider graph for each nutrient and I want each spider graph to have a separate set of connected dots for each year. As I understand things now, in ggRadar, the code mapping = aes(colour = year) is what gives separate dots for each year. in facet_wrap the code facet_wrap(~ nutrient) is what determines how many separate spider graphs there

Princomp error in R : covariance matrix is not non-negative definite

久未见 提交于 2021-02-19 02:36:18
问题 I have this script which does a simple PCA analysis on number of variables and at the end attaches two coordinates and two other columns(presence, NZ_Field) to the output file. I have done this many times before but now its giving me this error: I understand that it means there are negative eigenvalues. I looked at similar posts which suggest to use na.omit but it didn't work. I have uploaded the "biodata.Rdata" file here: covariance matrix is not non-negative definite https://www.dropbox.com

ggplot2: blurry facet labels

旧时模样 提交于 2021-02-19 02:34:13
问题 When I save a ggplot figure -- regardless of whether I use ggsave() or e.g. png() -- the facet labels come out looking blurry. For example, the following code produces a facet label 'F' that looks like the picture below, with coloration on the outer pixels of the text raster. ggplot(data.frame(x=1, y=1, f='F'), aes(x, y)) + facet_grid(. ~ f) ggsave('foo.png') Thanks in advance for any advice! PS -- As per @Brian's request, I'm updating this post to note that I'm using a Windows machine. PPS -

Merging of multiple excel files in R

て烟熏妆下的殇ゞ 提交于 2021-02-19 02:33:29
问题 I am getting a basic problem in R. I have to merge 72 excel files with similar data type having same variables. I have to merge them to a single data set in R. I have used the below code for merging but this seems NOT practical for so many files. Can anyone help me please? data1<-read.csv("D:/Customer_details1/data-01.csv") data2<-read.csv("D:/Customer_details2/data-02.csv") data3<-read.csv("D:/Customer_details3/data-03.csv") data_merged<-merge(data1,data2,all.x = TRUE, all.y = TRUE) data

Displaying cyrillic in RStudio console

断了今生、忘了曾经 提交于 2021-02-19 02:32:21
问题 I am having trouble displaying Russian characters in the Rstudio console. I load an Excel file with Russian using the readxl package. The cyrillic displays properly in the dataframe. However, if I run a function that has an output that includes the variable names, the RStudio consoles displays symbols instead of the proper Cyrillic characters. test.xlsx contains two columns - зависимая переменная (dependent variable - numeric) and независимая переменная (independent variable, factor).

Discrepancy between R's Keras and Python's Keras — Accuracy bug?

我们两清 提交于 2021-02-19 02:31:20
问题 I'm playing with some 2D CNN using Keras to predict Bike Sharing Demand. R performs very poorly vs Python, which reach good accuracy easily. I thought it was because of arrays shape (and some differences between R and Python), so I play with that for a while, ultimately using all possible shapes. I created the CombinationGrid object elsewhere and it looks like this: +------+------+------+------+-------+ | Dim1 | Dim2 | Dim3 | Dim4 | Order | +------+------+------+------+-------+ | 8887 | 3 | 2

Specifying positive class of an outcome variable in caret train()

允我心安 提交于 2021-02-19 02:29:51
问题 I'm wondering if there is a way to specify which class of the outcome variable is positive in caret's train() function. A minimal example: # Settings ctrl <- trainControl(method = "repeatedcv", number = 10, savePredictions = TRUE, summaryFunction = twoClassSummary, classProbs = TRUE) # Data data <- mtcars %>% mutate(am = factor(am, levels = c(0,1), labels = c("automatic", "manual"), ordered = T)) # Train set.seed(123) model1 <- train(am ~ disp + wt, data = data, method = "glm", family =

RStudio v1.1.456 Rpubs upload error, no login prompt

房东的猫 提交于 2021-02-19 02:27:07
问题 Hi I couldn't find any useful information in regards to this one. When I try to publish to Rpubs on Rstudio v1.1.456, instead of login prompt I get this error message below. [Edited] Rstudio v1.1.456, R v3.5.1 Upload Error Occurred Error in if (result$status == 201) succeeded <- TRUE : missing value where TRUE/FALSE needed Calls: In addition: Warning message: In http(protocol, "api.rpubs.com", port, method, path, headers, : NAs introduced by coercion Execution halted I've already addded this

R: using corrplot to visualize two variables (e.g., correlation and p-value) using the size and colour of the circles

ε祈祈猫儿з 提交于 2021-02-19 02:24:28
问题 I am trying to recreate someone's image using corrplot. This is the original image I am trying to re-create: I use the following R-code: corrplot(as.matrix(rgs), method="circle", type="upper", col=brewer.pal(n=8, name="PuOr"), tl.col="black", tl.srt=45, p.mat = as.matrix(pvalues), sig.level = 0.05, insig = "blank") Which gives me this: The problem I have is that the colour as well as the size of the circles in my plot are based on the correlations, but in the original image above the colour