Creating Index Variable in R [duplicate]

Do you just want to code the table up? Would something like this suffice?: PCP <- c(0, 4.9, 5, 9.9, 10, 14.9, 15) seq2max <- seq(0,max(PCP)+5,5) result <- data.frame(min=seq2max,max=seq2max+4.9,DRI=seq_along(seq2max)-1) min max DRI 1 0 4.9 0 2 5 9.9 1 3 10 14.9 2 4 15 19.9 3 5 20 24.9 4 result$DRI # [1] … Read more

Line graph with ggplot2 in R Studio [closed]

Next time please include the head this can be done using head(Store_sales) ProductID category sales product 1 101 Bakery 9468 White bread 2 102 Personal Care 9390 Everday Female deodorant 3 103 Cereal 9372 Weetabix 4 104 Produce 9276 Apple 5 105 Meat 9268 Chicken Breasts 6 106 Bakery 9252 Pankcakes I reproduced relevant fields … Read more

Sum by two variables

In base R (for sum) there’s xtabs: > xtabs(sales ~ Date + area, mydf) area Date beijing shanghai 201204 41 23 201205 17 71 To get it as a data.frame, wrap it in as.data.frame.matrix. To update this with the approach that is making the rounds these days, you can also use a combination of “dplyr” … Read more

How to reproduce a table of student? [closed]

Something like x <- 1:20; names(x) <-x y <- c(0.05, 0.025, 0.01, 0.005, 0.001, 0.0005); names(y) <- y outer(x, y,function(x, y) {abs(qt(y, df=x))}) #> 0.05 0.025 0.01 0.005 0.001 5e-04 #> 1 6.313752 12.706205 31.820516 63.656741 318.308839 636.619249 #> 2 2.919986 4.302653 6.964557 9.924843 22.327125 31.599055 #> 3 2.353363 3.182446 4.540703 5.840909 10.214532 12.923979 #> … Read more

In R, how to turn characters (grades) into a number and put in a separate column

Often you can use a named vector to do these sorts of mapping operations simply: students <- data.frame(name=c(“J. Holly”,”H. Kally”, “P. Spertson”, “A. Hikh”, “R. Wizht”), CRSE_GRADE_OFF=c(“A”,”D”,”E”,”A”,”A”)) scores = c(A=1, B=2, C=3, D=4, E=5, F=6) students$grade <- scores[as.character(students$CRSE_GRADE_OFF)] students # name CRSE_GRADE_OFF grade # 1 J. Holly A 1 # 2 H. Kally D 4 … Read more

How can I generate a user password in R [closed]

genPsw <- function(num, len=8) { myArr <- c(“”, 2, 3, 4, 5, 6, 7, 8, 9, “A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”, “J”, “K”, “L”, “M”, “N”, “P”, “Q”, “R”, “S”, “T”, “U”, “V”, “W”, “X”, “Y”, “Z”, “a”, “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “j”, “k”, “l”, “m”, “n”, “o”, … Read more

Several questions on ggplot2 [closed]

Have a look at scale_color_manual, the examples should be sufficient. The general structure of tweaking any scale in ggplot2 is to use the appropriate scale function: scale_{aes_name}_{scale_type}, where aes_name can be color, x, or any other aeshetic, and where scale_type can be continuous, discrete, manual, etc. Googling for ggplot2 legend position led me to this … Read more

How can the facet function in ggplot be used to create a histogram in order to visualize distributions for all variables in a dataset?

I’ve copied the data from your post above so you can skip the variable assignment library(“tidyverse”) df <- read.table(file = “clipboard”, header = T) %>% as_tibble() You need to modify your data structure slightly before you pass it to ggplot. Get each of your test names into a single variable with tidyr::gather. Then pipe to … Read more