Getting text from DataFrame

Jul 16, 2012 at 1:52 PM
Edited Jul 16, 2012 at 1:53 PM

I'm trying to get text information from a DataFrame but instead just get integers.

engine.Evaluate("library(ggplot2)");
engine.Evaluate("data(mpg)");
DataFrame df = engine.GetSymbol("mpg").AsDataFrame();

I know that the first column of the data frame, 'mpg' should contain the names of different car manufacturers. I've also tried to get each column of the R data frame using,

 

 

CharacterVector s = engine.Evaluate("mpg$manufacturer").AsCharacter(); 

 

 

but this also returns an array of integers. Am I missing something?

 

I'm working in VS2010 with the latest R.Net source code(654d70859417) to avoid this problem, http://rdotnet.codeplex.com/discussions/262846 and R 2.15.1

 

Thanks

 

George

Jul 16, 2012 at 11:24 PM

Hi George,

I am not sure how this should work, but manufacturer is a factor, which are numeric.

> mode(mpg$manufacturer)
[1] "numeric"

Perhaps if you used the R commnad   "as.character(mpg$manufacturer)"  instead.

Regards,

Rob

 

Jul 17, 2012 at 8:13 AM

Hi Rob,

You're right, and your suggested code does get the factor labels.  I should have realised this was the problem as this factor issue has confused me in the past when getting to grips with R.

By the way it seems that R.Net always gets the data frame as the numeric values, even getting the R dataframe as a CharacterMatrix, results in a string of the factor levels.

Many thanks for your help

 

George