r

Use dplyr to take first and last row in a sequence by group [duplicate]

好久不见. 提交于 2021-02-10 14:51:54
问题 This question already has answers here : Subset panel data by group [duplicate] (3 answers) Closed 1 year ago . I'm trying to use dplyr to take the first and last rows of repeated values by group. I'm doing this for efficiency reasons, particularly so that graphing is faster. This is not a duplicate of Select first and last row from grouped data because I'm not asking for the strict first and last row in a group; I'm asking for the first and last row in a group by level (in my case 1's and 0

How to Draw a three-dimensional graph in R

徘徊边缘 提交于 2021-02-10 14:49:03
问题 f(x,y)= (1/25)*(20-x)/x 10<x<20, x/2 <y <x 0 o.t I have to create this image through this expression. but x <- seq(10, 20, length=20) y <- seq(10, 20, length=20) f <- function(x,y){(1/25)*(20-x)/5} z <- outer(x,y,f) persp(x,y,z,theta=30,phi=30, expand=0.5,col=rainbow(19), border=NA) what is wrong? 回答1: You should mask z based on the constraint. As a suggestion, you can use an amazing interactive rgl package in R. #source: https://stackoverflow.com/questions/50079316/plot3d-how-to-change-z

corrupted UTF characters in pdf plots generated by R

女生的网名这么多〃 提交于 2021-02-10 14:48:52
问题 I am trying to save plots with legends containing UTF characters for Males and Females to pdf in R . When I plot to graphics device : plot(1) legend('topright', bty = 'n', expression(italic("legend"~"\u2640"~"\u2642"))) the legend of plot looks as expected I can even save it to pdf by right click and "save to pdf". However, when I use inbuilt function pdf pdf('test.pdf') plot(1) legend('topright', bty = 'n', expression(italic("legend"~"\u2640"~"\u2642"))) dev.off() it drops a warning and

How to Draw a three-dimensional graph in R

萝らか妹 提交于 2021-02-10 14:48:38
问题 f(x,y)= (1/25)*(20-x)/x 10<x<20, x/2 <y <x 0 o.t I have to create this image through this expression. but x <- seq(10, 20, length=20) y <- seq(10, 20, length=20) f <- function(x,y){(1/25)*(20-x)/5} z <- outer(x,y,f) persp(x,y,z,theta=30,phi=30, expand=0.5,col=rainbow(19), border=NA) what is wrong? 回答1: You should mask z based on the constraint. As a suggestion, you can use an amazing interactive rgl package in R. #source: https://stackoverflow.com/questions/50079316/plot3d-how-to-change-z

counting presence/absence based on group

强颜欢笑 提交于 2021-02-10 14:48:32
问题 I have a dataframe that contains abundance data of many species at two locations: sp1 sp2 sp3 sp4 SiteA 0 12 0 0 SiteA 0 3 0 0 SiteA 1 0 0 0 SiteB 0 0 6 0 SiteB 2 1 1 0 SiteB 0 1 0 8 I would like to calculate two things: how many species are found at each site. In this dummy example, there are two species at SiteA and four species at SiteB. the mean number of taxa in each row for each site. In this case, 1 for SiteA and 2 for SiteB. 回答1: I like using dplyr and the tidyverse packages for these

Adjust so that the condition panel appears only when a correct file is loaded

£可爱£侵袭症+ 提交于 2021-02-10 14:44:42
问题 I inserted a condition panel so that as soon as the file is loaded by fileInput. It is working, however, I would like this panel to be shown only when the correct file is loaded. As it is, even with the wrong format files, the condition panel appears, as shown in the image. Can someone help me?? The executable code is below: Thank you! library(shiny) library(shinyWidgets) library(ggplot2) library(shinythemes) library(rdist) library(openxlsx) library(geosphere) library(rgdal) function.cl<

Sorting of Bars-ggplot2 in shiny

你说的曾经没有我的故事 提交于 2021-02-10 14:44:37
问题 Please find the code below for a shiny App using ggplot2, I do not know how to sort them inside the server.R code. WIth the below code I am able to display the bar chart and change it but ordering the data seems to be an issue. ui.R library(shiny) library(ggplot2) shinyUI(fluidPage( column(12,offset=5, titlePanel("Template Type by Hours")), br(), h6(textOutput("text1")), fluidRow( column(4,offset=0, wellPanel( selectInput("var","Hours", choices = colnames(sum1[2:8]),selected ="hrs_0to1")))),

How to include plots in a new engine

老子叫甜甜 提交于 2021-02-10 14:42:00
问题 I'm writing a new engine for knitr. This engine can, depending on the input, generate a plot as either a ggplot object (list) or stored in a file (.png). I'm trying to output the image to the html (pdf, md) file that is generated by knitr but cannot find how. I've tried: include_graphics() with the path of the file return the ggplot object in engine_output() function knit_print() with many options nothing works! Here is the code of the engine. It's an engine for Ruby on GraalVM (Galaaz).

partykit - How to plot a glmtree without overlapping of terminal nodes?

我是研究僧i 提交于 2021-02-10 14:41:54
问题 I would like to plot a tree resulting from glmtree (partykit package). Unfortunately, the terminal nodes are overlapping and the labels of the graphs are no longer displayed properly. The code that generates the tree is this one: library(partykit) library(aVirtualTwins) data(sepsis) attach(sepsis) data <- cbind(y = survival, trt = as.factor(THERAPY), sepsis[,3:13]) formula <- as.formula(paste("y ~ trt", paste(names(sepsis[,3:13]), collapse = " + "), sep = " | ")) fit <- glmtree(formula, data,

postgres generate array using slide window

╄→гoц情女王★ 提交于 2021-02-10 14:41:09
问题 I'm trying to figure out how to a query to generate an ARRAY given a sliding window over a character column with Postgre. For example, if I have this: pid <chr> 1 WP_096038768.1 2 WP_013465871.1 3 WP_058155244.1 4 WP_011329269.1 5 WP_058374608.1 6 WP_089368983.1 7 WP_096739105.1 8 WP_089346667.1 9 WP_096041177.1 10 WP_010553306.1 ... I want a sliding window of size 1 before and after the row. The result is this: pid g <chr> <chr> 1 WP_013465871.1 WP_096038768.1,WP_013465871.1,WP_058155244.1 2