I would like to import CSV data into R in the form of an object of one dimension such as a vector. I only manage to import my data in the form of a table. I tried to convert the table into a vector, however it is not only challenging to my lack of expertise in R but also seems to lack parsimony for such a basic function.
Is there a straightforward way to accomplish this basic task, similar to the way c(x,y,z,...) works?
My data looks like the following (with 24,000 values): 1417656631000,0,0,3,20450,2,7,30798,2,2,7449,3,5,16002,2,1,77666,2,8,7435,4
We can import the data into R using the read_csv() function; this is part of the readr package, which is part of the tidyverse . Let's make a new script for this episode, by choosing the menu options File, New File, R Script. We see that the read_csv() table reports a “column specification”.
Importing data into R is fairly simple. For Stata and Systat, use the foreign package. For SPSS and SAS I would recommend the Hmisc package for ease and functionality. See the Quick-R section on packages, for information on obtaining and installing the these packages.
If you look at the package listing in the Packages panel, you will find a package called datasets. Simply check the checkbox next to the package name to load the package and gain access to the datasets. You can also click on the package name and RStudio will open a help file describing the datasets in this package.
You could use scan
op <- options(scipen=999)
res <- scan('yourfile.csv', what=numeric(), sep=",", quiet=TRUE)
res
#[1] 1417656631000 0 0 3 20450
#[6] 2 7 30798 2 2
#[11] 7449 3 5 16002 2
#[16] 1 77666 2 8 7435
#[21] 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With