Advertisement
jensyao

R code, working, defined Functs

Feb 9th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. import numpy as np
  2. np.__version__
  3. '1.11.3'
  4. %load_ext rpy2.ipython
  5. %R -o var var = 5
  6. array([ 5.])
  7. print(var)
  8. [ 5.]
  9. %R
  10. var=var*5
  11. var
  12. array([ 25.])
  13. print(var)
  14. [ 5.]
  15.  
  16. ==
  17.  
  18. input_arg_name=2
  19. %R -i input_arg_name -o output_arg_name output_arg_name= input_arg_name^4
  20. print(output_arg_name)
  21. [ 16.]
  22.  
  23.  
  24. def r_func(input_arg):
  25.     %R -i input_arg -o output_arg output_arg=input_arg^4
  26.     return output_arg[0]
  27. r_func(4)
  28.  
  29. 256.0
  30.  
  31. ==
  32.  
  33. %%R
  34. sum_vect <- function(a) {
  35.     b <- 0
  36.     for(i in 1:a){
  37.         b<-b+i^2
  38.     }
  39.     b
  40. }
  41. %R -o out out=sum_vect(3)
  42. print(out[0])
  43.  
  44. 14.0
  45.  
  46.  
  47. def sum_vector_in_r(arg):
  48.     %R -i arg -o out out=sum_vect(arg)
  49.     return out[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement