I have a tibble ('df') with
> dim(df)
[1] 55 144
of which I extract a vector test <- c(df[,39])
. I would expect the following result:
> length(test)
[1] 55
as I basically took column 39 from my tibble. Instead, I get
> length(test)
[1] 1
Now, class(test)
yielded list
, so I thought the class might be the reason; however, with class set to char
, I get the same result.
I'm especially confused since length(df[39,])
yields [1] 155
.
Background is I am searching in the vector using grep
, which doesn't work with a vector taken from a column. Of course, as I am trying to recode all lines in my tibble, I can recode them by row instead of by column, so I think there is a workaround. However, what causes R to assume that test
has length 1? What is the difference in the treatment of rows and columns?