Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between "Data" and "Values" in R

Tags:

I've recently transitioned from STATA to R. I am using RSTudio as my IDE. I found that some of my variables go into "Data" section in RStudio and some go into "Values." These are in the "Environment" window. I googled this a bit and found that there is some major concept in R that I am missing. What's the difference between "Data" and "Values"? It'll be great if someone could post an example when a variable will go to the Data section and when it would go to the Values section.

Here's the link I am referring to:https://support.rstudio.com/hc/en-us/community/posts/202201648-What-is-the-difference-between-Data-and-Values-in-the-Environment-pane-

I'd appreciate any thoughts.

like image 632
watchtower Avatar asked Jul 31 '16 19:07

watchtower


People also ask

What is the difference between data and value in R?

This is purely a difference in RStudio. 'Data' objects are S4 objects, environments, and objects with dimensions. There may be more, these are the few I have found so far. 'Value' objects are objects that are neither functions nor 'Data' objects.

What is the difference between data and value?

The element value attribute specifies the default value of the HTML element whereas the data attribute allows you to store extra data to tags in HTML when no other HTML attribute can do so.

How do you define a value in R?

In R, assigning values to a variable can be specified or achieved using the syntax of left angular brackets signifying the syntax of an arrow. After assigning values to a variable, these values can be printed using the predefined cat() function and print() function.

What are the different variables and data types in R?

R's basic data types are character, numeric, integer, complex, and logical. R's basic data structures include the vector, list, matrix, data frame, and factors.


2 Answers

You are not missing a "major concept in R". What you are missing is that RStudio has chosen for reasons of its own (thinking it was helping users no doubt) to segregate dataframes from other objects such as lists without the "data.frame" class. There is no "Data" or "Values" class in R and you won't find that distinction in the R Manuals. That's RStudio at work and not part of R. As I read the Jonathon-answer to the cited question, my guess is that the decision is based on whether the R object has a dimension attribute since he says matrices and frame would also be listed in "Values". I think a more accurate labeling would be "Dimensioned Objects" and "Non-dimensioned, non-language Objects". I was a bit surprised that lists get displayed but atomic vectors do not (contrary to Jonathon). Maybe there's a switch that can be thrown somewhere to display names of atomic vectors in that panel?

This goes in the Data section:

dat <- data.frame(a=1:10, b=letters[1:10]) 

And this would move it to the Values section:

dat <- unclass(dat) 

I will admit that there have been times when I wanted this information and (eventually) got it by running something like this:

> ls()[ lapply( mget( ls() ) , class) == "data.frame" ] [1] "air1"   "air2"   "dat"    "df"     "dfCord" "fsub"   "mtcars" "test"   
like image 68
IRTFM Avatar answered Nov 09 '22 09:11

IRTFM


This is purely a difference in RStudio. 'Data' objects are S4 objects, environments, and objects with dimensions. There may be more, these are the few I have found so far. 'Value' objects are objects that are neither functions nor 'Data' objects.

Edit : Upon further inspection, it appears as though 'Values' in RStudio are atomic objects with less than 2 dimensions. I hope this helps.

like image 32
Andrew Avatar answered Nov 09 '22 07:11

Andrew