Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I obtain vector from data.frame

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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"]].

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading