Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/Questions/Simple solutions for the warning message: ''attributes are not identical across measure variables; they will be dropped'' error.
Next
Answered
Isaac Jones
  • 21
Isaac Jones
Asked: May 18, 20222022-05-18T20:36:56+00:00 2022-05-18T20:36:56+00:00In: r

Simple solutions for the warning message: ”attributes are not identical across measure variables; they will be dropped” error.

  • 21

I am working on r, but I found the following warning message:

library(reshape2)
 test.m <- melt (test,id.vars=c('park'))
 Warning message:
 attributes are not identical across measure variables; they will be dropped

Is there any way to stabilize the issue “warning message: attributes are not identical across measure variables; they will be dropped”? I read a lot of topics about this, but all of them were trying to install anything. Is this the correct way, or any recommendation for me? Please find the beginning command below:

test <- structure(list(park = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
 1L, 1L, 1L), .Label = c("miss", "piro", "sacn", "slbe"), class = "factor"), 
  a1.one = structure(c(3L, 1L, 3L, 3L, 3L, 3L, 1L, 3L, 3L, 
  3L), .Label = c("agriculture", "beaver", "development", "flooding", 
  "forest_pathogen", "harvest_00_20", "harvest_30_60", "harvest_70_90", 
  "none"), class = "factor"), a2.one = structure(c(6L, 6L, 
  6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L), .Label = c("development", 
  "forest_pathogen", "harvest_00_20", "harvest_30_60", "harvest_70_90", 
  "none"), class = "factor"), a3.one = structure(c(3L, 3L, 
  3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("forest_pathogen", 
  "harvest_00_20", "none"), class = "factor"), a1.two = structure(c(3L, 
  3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("agriculture", 
  "beaver", "development", "flooding", "forest_pathogen", "harvest_00_20", 
  "harvest_30_60", "harvest_70_90", "none"), class = "factor"), 
  a2.two = structure(c(6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
  6L), .Label = c("development", "forest_pathogen", "harvest_00_20", 
  "harvest_30_60", "harvest_70_90", "none"), class = "factor"), 
  a3.two = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
  3L), .Label = c("forest_pathogen", "harvest_00_20", "none"
  ), class = "factor")), .Names = c("park", "a1.one", "a2.one", 
 "a3.one", "a1.two", "a2.two", "a3.two"), row.names = c(NA, 10L
 ), class = "data.frame")
str(test)
 'data.frame': 10 obs. of 7 variables:
  $ park : Factor w/ 4 levels "miss","piro",..: 1 1 1 1 1 1 1 1 1 1
  $ a1.one: Factor w/ 9 levels "agriculture",..: 3 1 3 3 3 3 1 3 3 3
  $ a2.one: Factor w/ 6 levels "development",..: 6 6 6 6 6 6 6 6 6 6
  $ a3.one: Factor w/ 3 levels "forest_pathogen",..: 3 3 3 3 3 3 3 3 3 3
  $ a1.two: Factor w/ 9 levels "agriculture",..: 3 3 3 3 3 3 3 3 3 3
  $ a2.two: Factor w/ 6 levels "development",..: 6 6 6 6 6 6 6 6 6 6
  $ a3.two: Factor w/ 3 levels "forest_pathogen",..: 3 3 3 3 3 3 3 3 3 3
 *** End Block ***
attributes are not identical across measure variables
  • 2 2 Answers
  • 179 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    lyytutoria Expert
    2022-06-27T03:05:27+00:00Added an answer on June 27, 2022 at 3:05 am

    The cause:

    You are having a trouble with this error because you combine several columns into one when you melt. You are merging factor columns in this instance, and each of those columns has a levels attribute. Because your components are really changeable across the columns, these levels are not similar. When forming the value column in the result, melt just forces each element to take on a character and discards its properties.

    Solution:

    When merging columns that are not the same “type”, which encompasses not just vector ”type” but also the general sort of items it refers to, you must exercise extreme caution.

    Asking yourself whether any potential values in one column would be a suitable value to have in each other column is a solution to determine whether it is okay to combine your factor columns or not. If that’s the case, probably you had better make sure that each factor column contains all of the levels that it could allow (in the same order). This will prevent you from receiving a notice when the table melt. Let’s follow the below example to understand clearly.

    library(reshape2)
    DF <- data.frame(id=1:3, x=letters[1:3], y=rev(letters)[1:3])
    str(DF)

    x and y levels are completely different:

    'data.frame': 3 obs. of 3 variables:
    $ id: int 1 2 3
    $ x : Factor w/ 3 levels "a","b","c": 1 2 3
    $ y : Factor w/ 3 levels "x","y","z": 3 2 1

    I melt here and let’s examine the column which was formed when x and y melted into (value):

    melt(DF, id.vars="id")$value

    I receive a character of vector and a warning message:

    [1] "a" "b" "c" "z" "y" "x"
    Warning message:
    attributes are not identical across measure variables; they will be dropped

    However, if I reset the factors so that their levels are similar and I only melt:

    DF[2:3] <- lapply(DF[2:3], factor, levels=letters)
    melt(DF, id.vars="id", factorsAsStrings=F)$value

    Then I get the exact factors and there is no warning for me:

    [1] a b c z y x
    Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z

    I use factorsAsStrings=F above because melt default behavior is to reduce factor levels even when they are similar. You would have received a character vector but no warning if you hadn’t used that setting. I suppose the default action here should keep the result as a consideration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Emma Rose
    2022-05-25T21:07:06+00:00Added an answer on May 25, 2022 at 9:07 pm

    BrodieG’s excellent answer is great. However, there are cases when it is not practical to refactor columns. For example, GHCN climate data has 128 columns fixed-width that I wanted to melt down into a smaller number of columns.

    The simplest way to deal with this situation is to treat data as characters, rather than factors. For example, read.fwf(filename,stringsAsFactors=FALSE) can be used to re-import data. This same process would apply for read.csv. You could use d$mystring<-as.character(d$myfactor) to convert factors into strings for a smaller number column.

    • 15
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.