Hi, I am new to R. Can anyone tell me how to evaluate an expression stored in a string? such as:
expr <- "3*5"
I want to get the result 15. Thanks in advance.
4 messages · Ning Ma, Sundar Dorai-Raj, ronggui
Hi, I am new to R. Can anyone tell me how to evaluate an expression stored in a string? such as:
expr <- "3*5"
I want to get the result 15. Thanks in advance.
Hi, Ning, Try: eval(parse(text = expr)) HTH, --sundar
Hi, I am new to R. Can anyone tell me how to evaluate an expression stored in a string? such as:
expr <- "3*5"
I want to get the result 15. Thanks in advance.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
eval(parse(text=expr))
[1] 15 2009/5/2 Ning Ma <pningma at gmail.com>:
Hi, I am new to R. Can anyone tell me how to evaluate an expression stored in a string? such as:
expr <- "3*5"
I want to get the result 15. Thanks in advance.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
HUANG Ronggui, Wincent PhD Candidate Dept of Public and Social Administration City University of Hong Kong Home page: http://asrr.r-forge.r-project.org/rghuang.html
Thank you and Sunder!
eval(parse(text=expr))
[1] 15 2009/5/2 Ning Ma <pningma at gmail.com>:
Hi, I am new to R. Can anyone tell me how to evaluate an expression stored in a string? such as:
expr <- "3*5"
I want to get the result 15. Thanks in advance.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
-- HUANG Ronggui, Wincent PhD Candidate Dept of Public and Social Administration City University of Hong Kong Home page: http://asrr.r-forge.r-project.org/rghuang.html