How to call ltm function using rpy package in python

Discussion in 'Python' started by Mohit Khanna, Jan 8, 2013.

  1. Mohit Khanna

    Mohit Khanna Guest

    I am trying the following code--

    from rpy import *
    r.library("ltm")

    dat= #some data frame or matrix
    r.ltm(r('dat~z1'))

    error coming is---
    RPy_RException: Error in eval(expr, envir, enclos) : object 'dat' not found

    Please tell me the right way to call ltm function using rpy library
    Mohit Khanna, Jan 8, 2013
    #1
    1. Advertising

  2. Mohit Khanna <> writes:

    > I am trying the following code--
    >
    > from rpy import *
    > r.library("ltm")
    >
    > dat= #some data frame or matrix
    > r.ltm(r('dat~z1'))
    >
    > error coming is---
    > RPy_RException: Error in eval(expr, envir, enclos) : object 'dat' not found
    >
    > Please tell me the right way to call ltm function using rpy library


    Your problem is that the 'dat' object is in the Python world but not in
    the R world. However, the expression r('dat~z1') is looking for a 'dat'
    object in the R world. So you must copy the Python object to the R
    world.

    I don't know if this will work in rpy, but it does work in rpy2. Rpy2
    has much better possibilities than rpy. But just try it:

    r['=']('dat', dat)
    r.ltm(r('dat~z1'))
    --
    Piet van Oostrum <>
    WWW: http://pietvanoostrum.com/
    PGP key: [8DAE142BE17999C4]
    Piet van Oostrum, Jan 11, 2013
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. malv
    Replies:
    0
    Views:
    332
  2. malv
    Replies:
    0
    Views:
    295
  3. Bo Peng
    Replies:
    1
    Views:
    457
    Bo Peng
    Jan 9, 2006
  4. jason

    RPy / R

    jason, Feb 7, 2006, in forum: Python
    Replies:
    4
    Views:
    559
    Eddie
    Feb 12, 2006
  5. Frank
    Replies:
    0
    Views:
    315
    Frank
    Mar 27, 2007
Loading...

Share This Page