Home > Mobile >  How can I obtain vector from data.frame
How can I obtain vector from data.frame

Time:12-09

input

side <- c("ABC DEF", "XYZ", "GHF")

output

[1] "ABC DEF" "XYZ"       "GHF"  

Now that I am importing data from excel, it is appearing as following using the given code:

library("xlsx2dfs")
Mydata <- read.xlsx("Data.xlsx",sheet =1, rows=1:4)

                Name
1            ABC DEF
2                XYZ
3                GHF

How do i have the same output while importing from excel file. Also I want to delete headers whereby there are no headers in the file. Please help

CodePudding user response:

First of all and most important I think is that when you write "I used to make dataframe using the following code" you have to know it's not true - this way you are not creating data.frame object, but vector of values. You can think - maybe you know this - of data.frame as of table consists of rows and columns. And you can think of columns as a vectors - each column is a vector. Knowing this, you can ask: "how can I obtain vector from data.frame" and this is what @user2974951 showed in the comment - syntax is my_data_frame$my_column or my_data_frame[["my_column"]].

  •  Tags:  
  • r
  • Related