Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: number of columns of result is not a multiple of vector length (arg 1)

Tags:

r

I am trying to split a column. my data frame (menuD) is like

Column1
1|3|4|5
4|5|6|7

I wanted to split the numbers in column1 so I did this.

menuD <- data.frame (do.call('rbind', strsplit(as.character(myCmenu$myFile.menudata), '|', fixed = TRUE)))

I got the expected result which is like this

col1 | col2 | col3 | col4
  1  |  3   |  4   | 5
  4  |  5   |  6   | 7

But I got this warning message from R

> Warning message:
In rbind(c("", "164200", "", "167", "108", "112", "116", "120"),  :
  number of columns of result is not a multiple of vector length (arg 1)

I'd like to know, did this effect my data? is all the data separated properly?

like image 986
Rayan Sp Avatar asked Oct 22 '25 06:10

Rayan Sp


1 Answers

Based on the example provided, either cSplit

library(splitstackshape)
cSplit(menuD, "Column1", "|")
#   Column1_1 Column1_2 Column1_3 Column1_4
#1:         1         3         4         5
#2:         4         5         6         7

Or separate from tidyr

library(tidyr)
separate(menuD, Column1, into = paste0("col", 1:4))

Or read.table/read.csv can be used.

read.table(text=menuD$Column1, sep="|", fill=TRUE, header=FALSE)

But, the warning in the OP's post indicates that there might be elements in the "Column1" with less number of |. In that case, the cSplit or the last option should work.

like image 79
akrun Avatar answered Oct 23 '25 18:10

akrun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!