# Sort a matrix by descending value for every row in order

I have a matrix which I want ordered by every column. Probably better to show the before and after. This is the matrix before. thematrix_before <- structure(c(0, 0, 0, 0, 0, 0.44, 0.68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.42, 0.39, 0, 0, 0, 0, 0, 0.35, 0, 0, 0,… Read More Sort a matrix by descending value for every row in order

# how to write "2023-9-15 00:00:00" by R

I am new for R, now I want to write a time like "2023-09-15 00:00:00", so I write the code time1<- as.POSIXct("2013-9-15 00:00:00",format="%Y-%m-%d %H:%M:%OS") print(time1) # [1] "2013-09-15 CST" but it’s not run. I’d appreciate it if you could help me. >Solution : time1 <- as.POSIXct("2013-9-15 00:00:00") time2 <- format(time1, "%Y-%m-%d %H:%M:%OS") print(time2)

# how to filter rows that have only 2 or more columns equal to 1?

I have a data frame with 5 columns x1 … x5. All of them are dummy variables. I want to filter rows only when 2 or more columns are equal to 1. For example, from df, only rows 1, 4 and 10 would be selected because: row 1, x2 = 1, x3 = 1, x4… Read More how to filter rows that have only 2 or more columns equal to 1?

# How to add a value from a row to the previous one in a column in R?

I have a dataset similar to the dataset below, Row Date Value 1 2022-01-03 400 2 2022-01-04 350 3 2022-01-05 368 4 2022-01-06 418 … I would like to calculate B by using a formula like below B = ((Value2 + Value1) / 2) + ((Value3 + Value2) / 2) + ((Value4 + Value3) /… Read More How to add a value from a row to the previous one in a column in R?

# Can't save a radar chart using RStudio and got a blank chart

I just start coding on RStudio, and I tried to draw a radar chart from a csv. The thing is, I want to use a loop to produce all my charts together, and save them in the same file, but all I get is 32 blank pictures. This is a screenshot of my csv: enter… Read More Can't save a radar chart using RStudio and got a blank chart

# R: Values on Graph Do Not Match Data

I am working with the R programming language. I have the following data: var1 = c(5,5,8,13,14,12,11,10,9,9,8,8) var2 = c(13,13,22,30,35,31,25,24,20,20,20,21) var1 <- ts(var1, start = 2010, frequency = 12) var2 <- ts(var2, start = 2010, frequency = 12) df = cbind(var1,var2) var1 var2 Jan 2010 5 13 Feb 2010 5 13 Mar 2010 8 22 Apr… Read More R: Values on Graph Do Not Match Data

# R Error: Unsupported type passed to argument 'data'

I am working with the R programming language. I am following the tutorial here https://rstudio.github.io/dygraphs/ to make the following graph: I tried to simulate some data for this example: library(dygraphs) set.seed(1) date <- seq(as.Date("2010-01-01"), as.Date("2010-12-01"), by = "month") var1 <- rnorm(length(date), mean = 100, sd = 10) var2 <- rnorm(length(date), mean = 50, sd =… Read More R Error: Unsupported type passed to argument 'data'

# R summary command doesn't show details of character variable

in R when I use summary(data.frame) command the results don’t show the details of character variables. for example summary(b) don’t show how many male or female are there? example of my problem problem? how can i solve this problem? >Solution : Assuming you used a dummy for gender gender_counts <- table(your_data\$gender) Then you can use… Read More R summary command doesn't show details of character variable

# Error when trying to reference a variable/column inside a function

In R, I am trying find the maximum value of a variable in a dataset inside a function but I can’t figure out the correct way to reference the variable. df <- data.frame(a = 1:3, b = 2:4) I’ve written the function as f <- function(var) { m <- max(df\${{var}}) if (m == 3) {… Read More Error when trying to reference a variable/column inside a function