Your error was thrown by the as.data.frame()
function. Data frames in R have to have columns with the same number of rows.
Given the error message: strsplit(as.character(rawdata_r$File),"_")
has produced a list with 1, 4, 5, and 2 nested elements. This suggests that rawdata_r$File
is a factor, that you're converting to character. The length of the character vector is 4, and the elements have 0, 3, 4, and 1 "_" in them respectively. Perhaps these are words in snake_case
Depending on what you want to use this object for, I would suggest just removing the call to data.frame
, and the call to t
. If you want to convert filenames using a snake_case naming convention to their words
See the following example:
# create an object with similar characteristics
filenames <- factor(c("foo", "foo_bar_baz_fiz", "foo_bar_baz_fiz_buz", "hello_world"))
# generate the error:
splits <- t(as.data.frame(strsplit(as.character(filenames),"_")))
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, :
arguments imply differing number of rows: 1, 4, 5, 2
# don't generate the error
splits <- strsplit(as.character(filenames), "_")
splits
[[1]]
[1] "foo"
[[2]]
[1] "foo" "bar" "baz" "fiz"
[[3]]
[1] "foo" "bar" "baz" "fiz" "buz"
[[4]]
[1] "hello" "world"