r

ggvis is not rendering anything in the viewer pane in RStudio

耗尽温柔 提交于 2021-02-17 05:22:10
问题 I am not able to get any points when I plot my ggvis . Please see my code below: #install.packages("ggvis", dependencies = T) #install.packages("shiny", dependencies = T) #install.packages("htmltools", dependencies = T) #install.packages("tidyverse", dependencies = T) library(htmltools) library(shiny) library(tidyverse) library(ggvis) mtcars %>% ggvis(~wt, ~mpg) %>% layer_points() #then i get the blank image like below: I am on Windows 10, Rstudio is all up-to-date. I would greatly appreciate

Subtracting values group-wise by the average of each group in R

。_饼干妹妹 提交于 2021-02-17 05:19:27
问题 I am trying to subtract group means from each group's values. For example: > x <- data.frame('gene' = c('A','A','A','B','B','C','C','C'),'value' = c(32.3,31,30.5,25,22.1,20.5,21.2,19.8)) > x gene value 1 A 32.3 2 A 31.0 3 A 30.5 4 B 25.0 5 B 22.1 6 C 20.5 7 C 21.2 8 C 19.8 I can find the group means: > aggregate(x[,2],list(x$gene),mean) Group.1 x 1 A 31.26667 2 B 23.55000 3 C 20.50000 How do I subtract the "value" in x by the corresponding group mean? My desire result is as follow: gene value

How can I transform columns into a sum conditional on the values in another numeric column?

∥☆過路亽.° 提交于 2021-02-17 05:17:08
问题 I have a dataframe designed to compare tickets between two years. df<-data.frame(year=c("1","2","1","2","1","2"), Daysleft=c(8,8,7,7,6,6), Count_TypeA=c(1,1,1,1,1,1), Count_TypeB=c(5,2,5,2,5,2)) In this example data frame, days left indicates days remaining until the event. What I'd like to do is come up with the cumulative counts where Daysleft >= the Daysleft value, grouped by year. The desired output is below: desired<-data.frame(year=c("1","2","1","2","1","2"), Daysleft=c(8,8,7,7,6,6),

Check whether a website provides photo or video based on a pattern in its URL

夙愿已清 提交于 2021-02-17 05:15:13
问题 I am wondering how I can figure out if a website provide photo or video by checking its URL. I investigated the website that I am interested in and found that most of the links I have are in this form: (I am not sure if I can actually name the website, so for now I just wrote it in a form of an example): http://www.example.com/abcdef where example is the main domain and abcdef is a number like 69964. The interesting pattern I found is that after entering this URL, if it actually has video the

Check whether a website provides photo or video based on a pattern in its URL

…衆ロ難τιáo~ 提交于 2021-02-17 05:15:09
问题 I am wondering how I can figure out if a website provide photo or video by checking its URL. I investigated the website that I am interested in and found that most of the links I have are in this form: (I am not sure if I can actually name the website, so for now I just wrote it in a form of an example): http://www.example.com/abcdef where example is the main domain and abcdef is a number like 69964. The interesting pattern I found is that after entering this URL, if it actually has video the

R error: “Error in check.data : Argument Should be Numeric”

微笑、不失礼 提交于 2021-02-17 05:14:45
问题 I am learning about the "kohonen" library for the R programming language. I created some artificial data to try some of the functions on. I tried using the "supersom()" function on only continuous (i.e type = as.numeric) data and everything works well. However, when I tried to run the "supersom()" function on both continuous and categorical (type = as.factor), I start to run into some errors ("Argument data should be numeric"). The "supersom()" function has an argument called "dist.fct"

Passing variable in function to other function variables in R

丶灬走出姿态 提交于 2021-02-17 05:14:22
问题 I am trying to pass a variable Phyla (which is also the name of a df column of interest) into other functions. However I get the error: Error: Column tax_level is unknown . Which I understand. It would just be more convenient to state the column you want to use once in the function since this will also be repeated numerous times in the script. I Have tried using OTU_melt_grouped[,1] since this will always be the first column to use in the dcast function, but get the error: Error: Must use a

Flatten nested JSON to dataframe in R

与世无争的帅哥 提交于 2021-02-17 05:10:56
问题 I am trying to flatten a nested JSON file from within R, Here is my current code library(jsonlite) json_file <- "json file" json_data = fromJSON(json_file, flatten = FALSE) flat_data = as.data.frame(json_data) However i am getting the below error flat_data = as.data.frame(json_data) Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows: 1, 13, 3201 Here is a sample of my JSON structure { "RIDE":{ "STARTTIME":"2020\/01\/05

Flatten nested JSON to dataframe in R

萝らか妹 提交于 2021-02-17 05:10:18
问题 I am trying to flatten a nested JSON file from within R, Here is my current code library(jsonlite) json_file <- "json file" json_data = fromJSON(json_file, flatten = FALSE) flat_data = as.data.frame(json_data) However i am getting the below error flat_data = as.data.frame(json_data) Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows: 1, 13, 3201 Here is a sample of my JSON structure { "RIDE":{ "STARTTIME":"2020\/01\/05

I Want to set and Automate Seed as a Vector Instead of an Integer in R

旧巷老猫 提交于 2021-02-17 05:10:12
问题 Using an arima.sim() function to simulate time series data that follows a particular ARIMA model requires a lot of trials of this nature: library(forecast) set.seed(1) ar1 <- arima.sim(n = 10, model=list(ar=0.2, order = c(1, 0, 0)), sd = 1) ar2 <- auto.arima(ar1, ic ="aicc") ar2 One needs to be changing the seed integer until the desired result is archived. I now think of instead of changing the seed integer manually and checking with auto.arima() function I should automate the seeds with a