Run any R Code Directly From This Forum

Post Reply
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#1

Run any R code from the box below or use this general-purpose interface

1
1 Image
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#2

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")

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#3

Here is the output

Image
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
Joseph Bundala
Expert Member
Reactions: 23
Posts: 55
Joined: 7 years ago
Has thanked: 14 times
Been thanked: 28 times
Contact:

#4

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?
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#5

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

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#6

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
Attachments
iris.png
iris.png (33.25 KiB) Viewed 27120 times
iris.png
iris.png (33.25 KiB) Viewed 27120 times
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
Avy_213
Member
Reactions: 1
Posts: 1
Joined: 2 years ago
Has thanked: 1 time

#7

Awesome code Elli!
1
1 Image
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#8

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")

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Return to “Technologies for Teaching, Learning, Research, Problem Solving and Business”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 15 guests