[Solved] Survival analysis [closed]

This should solve your problem: mod <- survreg((Surv(as.numeric(Time), event=Status)) ~ Prison+Dose+Clinic, data = meth, dist = “lognormal”) as you reported to me that: names(meth) # [1] “ID” “Clinic” “Status” “Time” “Prison” “Dose” Note, it is Time, not time; Also, it is Status, not status. In fact, all variables names start with a capital letter! 5 … Read more

[Solved] Side by side box plot in ggplot2 [closed]

To plot two plots (or more) in one figure, you can use the facet_grid function in ggplot2 (http://docs.ggplot2.org/current/facet_grid.html for more info). You can choose on which trait the plots will be facetted by using a formula. On the left hand side you can mention rows (graphs under each other) and on the left hand side … Read more

[Solved] How can I find compound words, removing spaces between them and replace them in my corpus?

If all your compound terms are separated only by blanks, you can use gsub: > x = c(“hello World”, “good Morning”, “good Night”) > y = gsub(pattern = ” “, replacement = “”, x = x) > print(y) [1] “helloWorld” “goodMorning” “goodNight” You can always add more patterns to pattern argument. Read more about regular … Read more

[Solved] Naming columns in a data table in R

I don’t word with data tables, but this is a solution that would work for data frames, and should hopefully generalize. The strategy is to use the fact that you can fill one vector with another vector, without ever having to use a loop. # make the example data sets D1 <- as.data.frame(matrix(data=(1:(20*181)), nrow=20, ncol=181)) … Read more

[Solved] Calculate simple function with R [closed]

As Brian Hannays says: Change the definition of Alive.prob to 1-Dead.prob. A good programming habit is to try to avoid redundant (and then possibly conflicting) definitions… function(Dead.prob=.010,Dead.cost=40000,Alive.prob=1-Dead.prob,Alive.cost=50000,high=100,p.payoff=1) { return((Dead.prob * Dead.cost) + (Alive.prob * Alive.cost)) } solved Calculate simple function with R [closed]

[Solved] How to access data in R from read.table

Is this what you want? : test <- read.table(“test.txt”, header = T, fill = T) for(i in 1:nrow(test)){ for(j in 1:ncol(test)) { print(test[i,j]) } } 2 solved How to access data in R from read.table

[Solved] Sudoku Solution Checker in R [closed]

Here is one. It uses the interesting property found here: https://math.stackexchange.com/a/157716 check.solutions <- function(solutions) { board <- matrix(1:81, 9, 9) row.idx <- row(board) col.idx <- col(board) squ.idx <- (row.idx – 1L) %/% 3L + 1L + 3L * (col.idx – 1L) %/% 3L grp.mat <- t(cbind(sapply(1:9, `==`, row.idx), sapply(1:9, `==`, col.idx), sapply(1:9, `==`, squ.idx))) flat.sol … Read more

[Solved] 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

[Solved] How can i create a contingency table in R? [closed]

You should give a reproducible example. Here some data: set.seed(1234) dat <- data.frame(Smoker=sample(c(‘Smoke’,’No_Smoke’),20,rep=TRUE), CANCER=sample(c(‘Cancer’,’NO_Cancer’),20,rep=TRUE)) Then using table you can get your contingency table: table(dat$Smoker,dat$CANCER) Cancer NO_Cancer No_Smoke 7 4 Smoke 5 4 For more information see ?table Description table uses the cross-classifying factors to build a contingency table of the counts at each combination of … Read more