r

Plotting likert scale questions and grouping them

自闭症网瘾萝莉.ら 提交于 2021-02-19 03:51:12
问题 I would like to create a plot, like is shown here: https://stats.stackexchange.com/a/25156, the stacked bar chart type. I have been trying to get it to work with the likert package all afternoon. I did manage to get a plot, but I couldn't get it to group by pre/post. Here's a sample of data: data <- structure(list(ID = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L), Survey = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L

R - How to create a seasonal plot - Different lines for years

ⅰ亾dé卋堺 提交于 2021-02-19 03:50:10
问题 I already asked the same question yesterday, but I didnt get any suggestions until now, so I decided to delete the old one and ask again, giving additional infos. So here again: I have a dataframe like this: Link to the original dataframe: https://megastore.uni-augsburg.de/get/JVu_V51GvQ/ Date DENI011 1 1993-01-01 9.946 2 1993-01-02 13.663 3 1993-01-03 6.502 4 1993-01-04 6.031 5 1993-01-05 15.241 6 1993-01-06 6.561 .... .... 6569 2010-12-26 44.113 6570 2010-12-27 34.764 6571 2010-12-28 51.659

How to set a theme when knitting RMarkdown to HTML?

北城以北 提交于 2021-02-19 03:50:06
问题 I have not been able to figure out how to set a knitr theme when converting RMarkdown to HTML. I have tried code such as > opts_knit$set(out.format = "html") > opts_chunk$set(highlight = TRUE) > knit_theme$set("olive") That does not affect the html output. I have tried this code before knitting the Rmd file as well as inside the first chunk. 回答1: Put a css file with the same name as your R file, but extension css, into the directory. Or see http://www.rstudio.com/ide/docs/authoring/markdown

Data.Table: Aggregate by every two weeks

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-19 03:43:10
问题 So let's take the following data.table. It has dates and a column of numbers. I'd like to get the week of each date and then aggregate (sum) of each two weeks. Date <- as.Date(c("1980-01-01", "1980-01-02", "1981-01-05", "1981-01-05", "1982-01-08", "1982-01-15", "1980-01-16", "1980-01-17", "1981-01-18", "1981-01-22", "1982-01-24", "1982-01-26")) Runoff <- c(2, 1, 0.1, 3, 2, 5, 1.5, 0.5, 0.3, 2, 1.5, 4) DT <- data.table(Date, Runoff) DT So from the date, I can easily get the year and week. DT[

R: Primitive Function - For Historical or Efficiency Reasons?

喜欢而已 提交于 2021-02-19 03:42:10
问题 How would I find list of primitive functions in R meant for historical or efficiency reasons? Primitive functions are the ones that provide links between R code and the C code used to write R. 回答1: This will get you the names of all R functions that wrap calls to .Primitive() : nms <- names(methods:::.BasicFunsList) ## ?.BasicFunsList for more info length(nms) # [1] 192 c(head(nms, 8), tail(nms, 8)) # [1] "$" "$<-" "[" "[<-" # [5] "[[" "[[<-" "%*%" "xtfrm" # [9] "switch" "tracemem" "unclass"

R sink(): Error, cannot split the message connection

好久不见. 提交于 2021-02-19 02:59:06
问题 I am trying to log the errors and warnings of an R script into an external file. At the same time I want to be able to see the errors and warnings in the console in RStudio (useful to develop and debug). I am trying to use the following code: logfile <- file("my_file_path", open="wt") sink(logfile, type="message", split = TRUE) But when I try to split the message connection using the funciton sink() I get the following error: Error in sink(logfile, type = "message", split = TRUE) : cannot

plotly click events from anywhere on the plot

纵然是瞬间 提交于 2021-02-19 02:57:49
问题 I am new to r-plotly and trying to figure out how to handle clicks which are not on the data. It seems that using event_data("plotly_click") I get events that are on points from the data, but so far have not figured out how to do this for clicks which are not close to the data, but just on the white part of the plot. Shiny click events from plots can do this and I just get the x and y of the click. I want similar, but for plotly plots. Can I specify click events to be from anywhere on the

Different fill orders in geom_bar per discrete x-value

十年热恋 提交于 2021-02-19 02:57:25
问题 I have this ggplot: What I want to do is change the order of cat2 in each distinct cat1 -category in decreasing order of share : For cat1 == Z: i would come first, because it has the largest share in that cat1 , followed by k , then j etc. For cat1 == Y: j would come first, because it has the largest share in that cat1 , followed by h , k , f , g and so on for all cat1-categories. I know I can control the order by defining factor levels, but since I need a different order in different cat1

aggregate less efficient than loops?

旧街凉风 提交于 2021-02-19 02:48:27
问题 I was trying to do this operation on a big table, to count rows with different combinations of a and b in a data.table X. Y <- aggregate(c ~ a+b,X,length) And it was taking forever (I stopped after 30 min) though RAM usage was still. Then I tried to loop manually through values of b and aggregate only on a (technically still aggregating on b but with a single value of b every time) : sub_agg <- list() unique_bs <- unique(X$b) for (b_it in unique_bs){ sub_agg[[length(sub_agg)+1]] <- aggregate

Turning one row into multiple rows in r [duplicate]

随声附和 提交于 2021-02-19 02:44:09
问题 This question already has answers here : Combine Multiple Columns Into Tidy Data [duplicate] (3 answers) Closed 3 years ago . In R, I have data where each person has multiple session dates, and the scores on some tests, but this is all in one row. I would like to change it so I have multiple rows with the persons info, but only one of the session dates and corresponding test scores, and do this for every person. Also, each person may have completed different number of sessions. Ex: ID Name