Page 1 of 1

Run any R Code Directly From This Forum

Posted: Wed Jul 22, 2020 8:42 pm
by Eli
Run any R code from the box below or use this general-purpose interface


Re: Run any R Code Directly From This Forum

Posted: Wed Sep 09, 2020 9:21 pm
by Eli
Test this R code, see here.

  1. # Define parameters and initial conditions
  2. a <- -8/3; b <- -10; c <- 28
  3. #Create a three-valued vector of initial conditions using c function
  4. yini <- c(X = 1, Y = 1, Z = 1)
  5. Lorenz <- function(t, y, parms){with (as.list(y), {dX <- a*X + Y*Z; dY <- b*(Y - Z); dZ <- -X*Y + c*Y - Z;
  6. list(c(dX, dY, dZ))})}
  7. library(deSolve)
  8. # We solve the IVP for 100 days producing the output after every 0.01 days
  9. times <- seq(from = 0, to = 100, by = 0.01)
  10. #Integrate
  11. out <- ode(y = yini, times = times, func = Lorenz, parms = NULL)
  12. # We check the output by printing out the first five lines
  13. head(out, n = 5)
  14. plot(out, lwd = 2)
  15. # Plot variables Y versus X to generate the famous butterfly
  16. plot(out[,"X"], out[,"Y"], type = "l", xlab = "X", ylab = "Y", main = "Butterfly")


Re: Run any R Code Directly From This Forum

Posted: Fri Sep 11, 2020 5:29 am
by Eli
Here is the output

Image

Re: Run any R Code Directly From This Forum

Posted: Tue Apr 27, 2021 4:55 pm
by Joseph Bundala
My laptop is dead, the only option is to use this platform at the moment for R analysis. @Eli, is it possible to add csv and port them in this editor?

Re: Run any R Code Directly From This Forum

Posted: Wed Apr 28, 2021 6:31 am
by Eli
Yes, you can use read.csv both here and using SageMath engine.

For example,

  1. df <- read.csv("https://github.com/selva86/datasets/raw/master/mtcars.csv")
  2. head(df)


will give you:

  1. mpg cyl disp  hp drat    wt  qsec vs am gear carb fast              cars
  2. 1 4.582576   6  160 110 3.90 2.620 16.46  0  1    4    4    1         Mazda RX4
  3. 2 4.582576   6  160 110 3.90 2.875 17.02  0  1    4    4    1     Mazda RX4 Wag
  4. 3 4.774935   4  108  93 3.85 2.320 18.61  1  1    4    1    1        Datsun 710
  5. 4 4.626013   6  258 110 3.08 3.215 19.44  1  0    3    1    1    Hornet 4 Drive
  6. 5 4.324350   8  360 175 3.15 3.440 17.02  0  0    3    2    1 Hornet Sportabout
  7. 6 4.254409   6  225 105 2.76 3.460 20.22  1  0    3    1    1           Valiant
  8.             carname
  9. 1         Mazda RX4
  10. 2     Mazda RX4 Wag
  11. 3        Datsun 710
  12. 4    Hornet 4 Drive
  13. 5 Hornet Sportabout
  14. 6           Valiant


Re: Run any R Code Directly From This Forum

Posted: Thu Apr 29, 2021 8:52 pm
by Eli
Try:

  1. #Let's explore the iris Data with R
  2. #Load required libraries
  3. library(datasets)
  4. data(iris)
  5. summary(iris)
  6. plot(iris)


Plot output

Re: Run any R Code Directly From This Forum

Posted: Wed Jan 12, 2022 1:06 am
by Avy_213
Awesome code Elli!

Re: Run any R Code Directly From This Forum

Posted: Wed Apr 19, 2023 5:52 pm
by Eli
What is the output ?

  1. my_print = function(ABCD){
  2.     print("MY NAME")
  3.     }
  4.  
  5. my_print()
  6.  
  7. my_print = function(a){
  8.     print(paste("MY NAME IS",a))
  9.   }
  10.  
  11. my_print("John")