Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the vector

length
# [1] 15,34, 12,24, 225,
# Levels: 12,24, 15,34, 225,

and I want to separate them by the comma to eventually make a list of these values

Tried:

strsplit(length, ",") 

but keep getting the error message

Error in strsplit(length, ",") : non-character argument
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
543 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your "length" object is a factor:

As the error message indicates, strsplit expects a character vector as the input.

Try:

strsplit(as.character(length), ",") 

Demo

x <- factor(c("1,2", "3,4", "5,6"))
strsplit(x, ",")
# Error in strsplit(x, ",") : non-character argument
strsplit(as.character(x), ",")
# [[1]]
# [1] "1" "2"
# 
# [[2]]
# [1] "3" "4"
# 
# [[3]]
# [1] "5" "6"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...