简体   繁体   中英

In R, how do you extract and combine strings from data frame columns into a new list?

I have a dataframe from which I am able to access the strings I've stored in various columns. For instance, adults$IDone and adults$IDtwo each produces all of the strings for each of those columns. However, when I try to combine those two sets of strings c(adults$IDone, adults$IDtwo) I get back numbers instead of the stored strings. I feel I must be completely misunderstanding something about how data frames work... Thanks in advance for any help!

adults$IDone and the other variable are factors. When you try to concatenate them with c() you get back their numeric representations. This is a common beginners problem.

You need to wrap them in as.character() to get your desired output.

c(as.character(adults$IDone), as.character(adults$IDtwo))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM