Ashim Kapoor
2017-Jun-04 10:48 UTC
[R] Warning from reshape2 when melting a data frame with uneven number of columns.
Here is a small reproducible example: data <- structure(list(V1 = structure(1:3, .Label = c("Name1", "Name2", "Name3"), class = "factor"), V2 = structure(c(1L, 3L, 2L), .Label c("nam1", "name-1", "name_12"), class = "factor"), V3 = structure(1:3, .Label c("nam2", "nam_34", "name-2"), class = "factor"), V4 = structure(c(2L, 3L, 1L), .Label = c("", "nam3", "nam_56"), class = "factor"), V5 = structure(c(1L, 2L, 1L), .Label = c("", "name_78"), class "factor")), .Names = c("V1", "V2", "V3", "V4", "V5"), class = "data.frame", row.names = c(NA, -3L)) library(reshape2) data_long <- melt(data,id.vars="V1") Warning message: attributes are not identical across measure variables; they will be dropped Can someone please tell me how to correct this? Best Regards, Ashim [[alternative HTML version deleted]]
John Kane
2017-Jun-04 14:44 UTC
[R] Warning from reshape2 when melting a data frame with uneven number of columns.
I am not really sure what the warning means but I think your underlying problem is that all your variables are factors. Did you intend the values in each variable to be character? data.frame':??? 3 obs. of? 5 variables: ?$ V1: Factor w/ 3 levels "Name1","Name2",..: 1 2 3 ?$ V2: Factor w/ 3 levels "nam1","name-1",..: 1 3 2 ?$ V3: Factor w/ 3 levels "nam2","nam_34",..: 1 2 3 ?$ V4: Factor w/ 3 levels "","nam3","nam_56": 2 3 1 ?$ V5: Factor w/ 2 levels "","name_78": 1 2 1 On Sunday, June 4, 2017 6:48 AM, Ashim Kapoor <ashimkapoor at gmail.com> wrote: Here is a small reproducible example: data <- structure(list(V1 = structure(1:3, .Label = c("Name1", "Name2", "Name3"), class = "factor"), V2 = structure(c(1L, 3L, 2L), .Label c("nam1", "name-1", "name_12"), class = "factor"), V3 = structure(1:3, .Label c("nam2", "nam_34", "name-2"), class = "factor"), V4 = structure(c(2L, 3L, 1L), .Label = c("", "nam3", "nam_56"), class = "factor"), ? ? V5 = structure(c(1L, 2L, 1L), .Label = c("", "name_78"), class "factor")), .Names = c("V1", "V2", "V3", "V4", "V5"), class = "data.frame", row.names = c(NA, -3L)) library(reshape2) data_long <- melt(data,id.vars="V1") Warning message: attributes are not identical across measure variables; they will be dropped Can someone please tell me how to correct this? Best Regards, Ashim ??? [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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. [[alternative HTML version deleted]]
Ashim Kapoor
2017-Jun-04 15:03 UTC
[R] Warning from reshape2 when melting a data frame with uneven number of columns.
Is this the solution?> d1<- as.data.frame(lapply(data,as.character),stringsAsFactors=FALSE) > str(d1)'data.frame': 3 obs. of 5 variables: $ V1: chr "Name1" "Name2" "Name3" $ V2: chr "nam1" "name_12" "name-1" $ V3: chr "nam2" "nam_34" "name-2" $ V4: chr "nam3" "nam_56" "" $ V5: chr "" "name_78" ""> melt(d1,id.vars="V1")V1 variable value 1 Name1 V2 nam1 2 Name2 V2 name_12 3 Name3 V2 name-1 4 Name1 V3 nam2 5 Name2 V3 nam_34 6 Name3 V3 name-2 7 Name1 V4 nam3 8 Name2 V4 nam_56 9 Name3 V4 10 Name1 V5 11 Name2 V5 name_78 12 Name3 V5>On Sun, Jun 4, 2017 at 8:14 PM, John Kane <jrkrideau at yahoo.ca> wrote:> I am not really sure what the warning means but I think your underlying > problem is that all your variables are factors. Did you intend the values > in each variable to be character? > data.frame': 3 obs. of 5 variables: > $ V1: Factor w/ 3 levels "Name1","Name2",..: 1 2 3 > $ V2: Factor w/ 3 levels "nam1","name-1",..: 1 3 2 > $ V3: Factor w/ 3 levels "nam2","nam_34",..: 1 2 3 > $ V4: Factor w/ 3 levels "","nam3","nam_56": 2 3 1 > $ V5: Factor w/ 2 levels "","name_78": 1 2 1 > > > > On Sunday, June 4, 2017 6:48 AM, Ashim Kapoor <ashimkapoor at gmail.com> > wrote: > > > Here is a small reproducible example: > > data <- > structure(list(V1 = structure(1:3, .Label = c("Name1", "Name2", > "Name3"), class = "factor"), V2 = structure(c(1L, 3L, 2L), .Label > c("nam1", > "name-1", "name_12"), class = "factor"), V3 = structure(1:3, .Label > c("nam2", > "nam_34", "name-2"), class = "factor"), V4 = structure(c(2L, > 3L, 1L), .Label = c("", "nam3", "nam_56"), class = "factor"), > V5 = structure(c(1L, 2L, 1L), .Label = c("", "name_78"), class > "factor")), .Names = c("V1", > "V2", "V3", "V4", "V5"), class = "data.frame", row.names = c(NA, > -3L)) > > library(reshape2) > data_long <- melt(data,id.vars="V1") > > Warning message: > attributes are not identical across measure variables; they will be dropped > > > Can someone please tell me how to correct this? > > Best Regards, > Ashim > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/ > posting-guide.html <http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > > >[[alternative HTML version deleted]]