Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
reference_book:r_coupling [2023/05/12 20:31]
chrystian Removed references to 'DinamicaEGO 4'
reference_book:r_coupling [2023/05/24 14:32]
chrystian Added an example demonstrating the use of the Calculate R Expression.
Line 28: Line 28:
 sudo apt install r-base sudo apt install r-base
 </​code>​ </​code>​
-Make sure that the installed version is **4.3 or higher**. For specific instructions on installing R, please refer to the following link [https://​cran.r-project.org/​bin/​linux/​ubuntu].+Make sure that the installed version is **4.3 or higher**. For specific instructions on installing R, please refer to the following link [ https://​cran.r-project.org/​bin/​linux/​ubuntu ].
  
 **4. Configure R in DinamicaEGO:​** Now, let's configure DinamicaEGO to use the R installation you just performed. **4. Configure R in DinamicaEGO:​** Now, let's configure DinamicaEGO to use the R installation you just performed.
Line 40: Line 40:
  
 Once the procedure above is complete, the R scripts can be used by Calculate R Expression Once the procedure above is complete, the R scripts can be used by Calculate R Expression
 +
 +===== Example: Calculate R Expression =====
 +You can use the Calculate R expression function using the following example:
 +
 +<​code>​
 +# Install and load the required packages
 +dinamicaPackage("​dplyr"​)
 +
 +# Read the table.
 +input <- read.csv(s1)
 +
 +# Print the table 
 +print(input)
 +
 +# Use the table connected to the Calculate Expression.
 +input2 = t1
 +
 +# Print the table 
 +print(input2)
 +
 +# Create a new table 
 +data <- data.frame(
 +  name = c("​John",​ "​Jane",​ "​Mike"​),​
 +  age = c(25, 30, 35),
 +  city = c("New York", "​London",​ "​Paris"​),​
 +  stringsAsFactors = FALSE
 +)
 +
 +# Print the table 
 +print(data)
 +
 +# Calculate the arithmetic mean of column1 using dplyr
 +mean_column1 <- data %>% summarise(mean_column1 = mean(age))
 +  ​
 +# Print the arithmetic mean of column1
 +print(mean_column1$mean_column1)
 +</​code>​
  
 ===== Exchanging Data between R and Dinamica ===== ===== Exchanging Data between R and Dinamica =====