I'm new to R.
我是R.的新手
I have a a Data.frame with a column called "Symbol".
我有一个Data.frame,其中包含一个名为“Symbol”的列。
Symbol
1 "IDEA"
2 "PFC"
3 "RPL"
4 "SOBHA"
I need to store its values as a vector(x = c("IDEA","PFC","RPL","SOBHA")
). Which is the most concise way of doing this?
我需要将其值存储为向量(x = c(“IDEA”,“PFC”,“RPL”,“SOBHA”))。这样做最简洁的方法是什么?
1 个解决方案
#1
30
your.data <- data.frame(Symbol = c("IDEA","PFC","RPL","SOBHA"))
new.variable <- as.vector(your.data$Symbol) # this will create a character vector
VitoshKa suggested to use the following code.
VitoshKa建议使用以下代码。
new.variable.v <- your.data$Symbol # this will retain the factor nature of the vector
What you want depends on what you need. If you are using this vector for further analysis or plotting, retaining the factor nature of the vector is a sensible solution.
你想要什么取决于你需要什么。如果您使用此向量进行进一步分析或绘图,保留向量的因子性质是一个明智的解决方案。
How these two methods differ:
这两种方法有何不同:
cat(new.variable.v)
#1 2 3 4
cat(new.variable)
#IDEA PFC RPL SOBHA
#1
30
your.data <- data.frame(Symbol = c("IDEA","PFC","RPL","SOBHA"))
new.variable <- as.vector(your.data$Symbol) # this will create a character vector
VitoshKa suggested to use the following code.
VitoshKa建议使用以下代码。
new.variable.v <- your.data$Symbol # this will retain the factor nature of the vector
What you want depends on what you need. If you are using this vector for further analysis or plotting, retaining the factor nature of the vector is a sensible solution.
你想要什么取决于你需要什么。如果您使用此向量进行进一步分析或绘图,保留向量的因子性质是一个明智的解决方案。
How these two methods differ:
这两种方法有何不同:
cat(new.variable.v)
#1 2 3 4
cat(new.variable)
#IDEA PFC RPL SOBHA