HomeОбразованиеRelated VideosMore From: MarinStatsLectures-R Programming & Statistics

# Importing , Checking and Working with Data in R | R Tutorial 1.7 | MarinStatsLectures

More From: MarinStatsLectures-R Programming & Statistics
1311 ratings | 341060 views
Html code for embedding videos on your blog
TheCooPeer (13 days ago)
Hey, I have a question about transforming values (for example equity, debt etc.).How can i transform those values that were saved as characters into numeric values?
saudia reyes (2 months ago)
hi sir martin! i am taking a masteral degree in information management. Your tutorial is a big help. thank you!
you're welcome, we're glad to hear that!
ChessIsLife (4 months ago)

thank u !!!! best tutorial ever seen in youtube, coursera or even in the college!
Ekaterina Kuznetsova (7 months ago)
Hi, I was wondering if you have a video on working with Panel Data in R and how to correctly import it from Excel?
Simonas Bingelis (7 months ago)
How do you let R know that the first column is also a header ? For example years.
Simonas Bingelis (7 months ago)
Thank you!
you use the *row.names* argument within the "read.table" command. here is the explanation from R-help, as they say it more clearly than i would: *row.names* a vector of row names. This can be a vector giving the actual row names, or a single number giving the column of the table which contains the row names, or character string giving the name of the table column containing the row names. If there is a header and the first row contains one fewer field than the number of columns, the first column in the input is used for the row names. Otherwise if row.names is missing, the rows are numbered.
Qaiser Ijaz (8 months ago)
how i fixed this permission denied message
Qaiser Ijaz (8 months ago)
Hi! i am getting the error message permission denied while running this command read.table
Qaiser Ijaz (8 months ago)
kindly upload caching the Mean of a vector and inverse matrix in R
Qaiser Ijaz (8 months ago)
Hi, thanks for reply ... it is working fine for me ... could you please upload video for inverse matrix function
Hi, it is hard to tell from a distance, but my best guess is that you are trying to import a file that you dont have "permission" to open. for example, the file may be in an "administrator account" and you are working in a different user account that doesn't have permission to access that file.
Soundararajan Mathiaru (9 months ago)
Thank you for the sharing your knowledge in a very simple and easy way to learn.
Nizam Uddin Nstu (9 months ago)
Sir can I get ur lungcapdata.txt file?So I can practice perfectly.. thanks sir
hari chandana g (10 months ago)
Nathan Horn (10 months ago)
3:30 is where it shows data import from a text file.
Mohit Dhanjani (10 months ago)
thank you sir, easy to understand and please add more complicated programming videos based on R
prerna maheshwari (10 months ago)
i am unable to get the output of levels- result is null and summary also provides me class:character, mode :character for gender,cesearean, smoke
Picasso Harbor (1 year ago)
they are so useful :3 Thank you share it with us :3
Thank you very much Sir. Good job. Very easy to understand.
Alan Le (1 year ago)
Does anyone know the keyboard shortcut on how he pasted the previous line of command into his console?
Debojit Chanda (1 year ago)
hi Marin, In my R console, its not showing the Workspace and the history like its showing for others. could you please help?
Ashley Ransom (1 year ago)
Thank you so much for these videos! I'm a grad student in psychology, and these are incredibly helpful!
Jithesh Kumar (1 year ago)
hey martin. How did the variable x appear in your work space upon using the 'names' function?
Jess.... how pratical and didactic you are! I can follow u very easy, Congrats!
thanks, appreciate that :)
Behrouz Ghanbari (1 year ago)
Dear Mike, thank you for great videos, in command: read.table(file.choose(),header=T, sep="\t"), I think the sign is a backslash \ not slash, please correct me if I am wrong.
harshit tilak (1 year ago)
how to save our r program u didn't tell , this thing must be teach in the beginning of tutorial .
Mohit Dhanjani (10 months ago)
there is an icon to the left side of "SOURCE ON SAVE" named save current document or shortcut for it is Ctrl+s
Sam Dave Pollard (1 year ago)
best_R_Tutor <- "Mike Marin"
Ben Schoemann (1 year ago)
Also, Mine only says 10 observations. Does anybody know why that might be. I just downloaded this program so I'm thinking it might have to do with no having all the plugins I need or something.
Ben Schoemann (1 year ago)
How do you find the path to a file?
Pinaki Agarwal (10 months ago)
https://www.pcworld.com/article/251406/windows_tips_copy_a_file_path_show_or_hide_extensions.html
ying Hare (1 year ago)
with Mac ,u can search the file ,then kick de mouse "right"one ,then you can find get info---then kick it, from the general u can find where
gaurav gregrath (1 year ago)
great job mate... i would love to watch all your videos... better thn ANY fu*k*ng online tuts available out there.. i wl donate someday soon aftr i get the job thru ur videos.. wish u can make videos on SAS , Python, SPSS
Edvan Aguiar (1 year ago)
How can I remove a column from a dataframe? i.e the first one.
Yameen Shah (1 year ago)
thanks good guide
ToniSkit (1 year ago)
When i try to use the built in import function Rstudio says " preparing data import requieres an updated version of the Rcpp package. " After installing, i keep getting the same prompt. Anyone having this problem? Not that it matters too much because of the file.choose(read... command but still would be nice to know why it happens.
Great job Mike! Thank you very much!
Hosse Huang (1 year ago)
Best R tutorial video online, thanks!!!
Pedro Fernandes (1 year ago)
how to do this with time series data?
Marin... Thank you very much. You are doing a great great great job for help people to have a grasp on R
thanks +Badra Sid, we appreciate that!
Great Job Marin ... Thank you so much.
Carsten Grube (1 year ago)
Thanks Mike for some great learning material. ... got the same issue as Chris Powley (3 ds ago) that the 'Smoke', 'Gender' and 'Caesarean' are being converted to CHARACTERS instead of as FACTORS in my LungCapData (which I have imported as csv - not able to import as txt.). Any suggestions? So many thanks!
Hi +Carsten Grube , you can tell R to treat it as a factor instead...just use *Gender <- as.factor(Gender)* if you've attached the data, and if you haven't (and are working with \$ instead, then use *LungCapData\$Gender <- as.factor(LungCapData\$Gender)*
Rob van Mechelen (1 year ago)
Appreciate your lectures very much. One comment you call a backslash a slash. I do not know why. "\t" = backslash t
Chris Powley (1 year ago)
Thanks for the great tutorials, I find when I import the text file it coverts the factor fields to characters. How can I make it important same way as your example?
Hi +Chris Powley , you can tell R to treat it as a factor instead...just use *Gender <- as.factor(Gender)* if you've attached the data, and if you haven't (and are working with \$ instead, then use *LungCapData\$Gender <- as.factor(LungCapData\$Gender)*
Jasmeet Singh Babra (1 year ago)
Great video! very easy to follow along. But how do you include different view windows in the console?
swathi muthyapu (1 year ago)
how can we import fixed length files into Rstudio?
Z Wang (1 year ago)
Thanks for your tutorial, but I have some issues when doing the tail(Lung..), in your video it shows the number of the last six column in the table that retrieved, such as 720-725, but in mine, it keep giving 1-6, this even happen when I use LungCapData[c(5,6,7,8,9), ] to retrieve the specific columns, it gives me 12345 as the column no. instead of 5,6,7,8,9 in the table I got. So do you have any idea about that? Thanks.
Z Wang (1 year ago)
Sorry, it should be row number instead of column.
Uma sankar (1 year ago)
Hii Marin while I importing data I got error like this can you please rectify this. > data1<-read.table(file="C:\Users\umasa\Desktop\LungCapDatatxt.txt",header=T,sep="\t") Error: '\U' used without hex digits in character string starting ""C:\U" Thanks Uma Sankar
Mohit Passi (1 year ago)
Sterracks (1 year ago)
Hi Marin! So I'm playing around with data imports in excel, and I'm trying to extract data from rows 1, 3, and 5. When I do this, the values are correct, but R labels the output as 1, 2, 3. Is there a fix?
Hello thank you Sir for nice video, I'm struggling on area to find word file on my excel and my computer asks me to add something else to import data from excel
mukong meh (1 year ago)
Great Video right there. Simple and straight to the point. Good job Mate.
thanks +mukong meh  !
Sreejesh Mohanan (1 year ago)
A perfect example of how a tutorial should be like. thumbs up!!!!
thanks +Sreejesh Mohanan !
Shashim Waghmare (2 years ago)
Can you give link for the datasets on which you perform operations in the tutorials
Shashim Waghmare (1 year ago)
ohh.. thank you
Hi Shashim, you can find the the link to the dataset in the description of the video ('show more') or the info in each video: if you press the little "i" on the top right corner in the video you will be able to find the link to the dataset. you can also visit our website for the datasets : http://www.statslectures.com/index.php
umgrandepino (2 years ago)
Hey Marin, I have a problem. When I import your file LungCapData, the variables Smoke, Gender, Caesarean are in a character form. I cannot calculate means here. How can I change this to a factor variable (0,1)?
shubham swami (2 years ago)
great work sir. I am from india. i really appreciate ur work.
good to hear, thanks +shubham swami !
Novice Programmer (2 years ago)
Hi, just a quick question re the usefulness of R.I am under the impression R is good at handling "large" data. By large, I mean in excess of 1million records, ie something Excel has problems with.What I don't understand is your preferred method of getting data into R.You state you like Excel (so do I!), so you typically get the data in Excel, save it as a csv then import it into R using read.table.But that would mean the size of your data you want to analyse is limited to what Excel can handle? Suppose you want to analyse data that contains 2million records (and is currently stored in Access or SQL Server). how would you import that into R?
YOON CHOI (2 years ago)
I cannot move forward from 0:55 because there is an error '\U' without hex digits in character string starting ""\U". Please let me know how to do this:(
YOON CHOI (2 years ago)
Thank you so much! I appreciate that
Hi +YOON CHOI , I'm sorry but i have no idea what the issue is...especially without knowing what commands you've entered, or what the error message is. but i would suggest to do one of the tow following things: 1) just import the data using the *import data* tab that is the the top right corner of RStudio. or 2) in the read.table command, instead of specifying the path to the file, just instead enter: *data <- read.table(file.choose(), header=T,...)*, and this will let you select the data from a menu instead of specifying the path to it. i show how to do both of these in this and/or following videos.
Berin Tabaković (2 years ago)
This is a great example of how tutorials on youtube should look! Thank you!
thanks +Berin Tabaković !
pranav dhananiwala (2 years ago)
great job mate! your videos. how can we import txt files if there are any missing values and when in few rows there are some colums more and less. can i get your emial id
priyabrata acharya (2 years ago)
Dear Marin...could you please let me know where can I get the LungCapData.txt (it seems to contain too much data)
puneet gupta (2 years ago)
such a nice and clear voice , thanks.
thanks +puneet gupta !
Songtao Yao (2 years ago)
Thank you so much, your lectures are very clear and easy to follow, even for me,a chinese.
that's great to hear +子衿卿卿 !
Mohammed Al-Hajri (2 years ago)
excellent tutorials. much appreciated.
Your R series is the best one ever.....Thnx a lot for your amazing tutorials!
thanks +Mohammad Gendy , we appreciate that!
Michael heslar (2 years ago)
Where has this R program been all my life. So much nicer than working with data in just Excel
yeah, it's a pretty powerful software, eh +Michael heslar ? Excel has its place, but not really useful for data analysis....and R has really come a long way over the past 10 years!
Omfg,this channel is awesome! Thank you!
thanks +Bromoteknada , we appreciate that!
Rod Fish (2 years ago)
truly amazing. SUBSCRIBED! Thank you so much
thanks +Rod Fish , appreciate that!
3 Foss (2 years ago)
Sorry Prof, If the values are separated with the";" how would i manage it. Cuase in this video you speak about ",", and "tab" used for delimitate. Thkls
3 Foss (2 years ago)
Great.
happy to help +3 Foss
3 Foss (2 years ago)
AH, OK THKS PROF.
Hi +3 Foss , in the *read.table* command, you will use *sep=";"* . (e.g.) *data <- read.table(file=".....", header=T, sep=";")*
Mohamed samir (2 years ago)
great tutorial and great effort
thanks +Mohamed samir !
srinivas varma (2 years ago)
marin i want ur lungcapacity data for better understanding ,can u please give a download link for ur luncap data,thanks in advance for giving and thanks for ur videos
srinivas varma (2 years ago)
+MarinStatsLectures thank u very much
Lynpe (2 years ago)
Hello. I keep getting an error message - Object "Data" not found. The data showed up but I am unable to do a box plot or anything else because it does not recognized the variable. I have gone through and renamed my data, but it is not recognized no matter what name I change it do in the data set. Any advice?
Hi +Lynette 3132 , it's hard to know the error without knowing what commands you've entered into R. but here's a few things that may help. 1) have you attached the data, (e.g.) *attach(data)* , (with the name of the data in place of 'data') ? if you haven't, then you wont be able to call on variables by their name. (in the video that follows this one in the series, i explain the use of the 'attach' command). 2) when importing the data, have you stored in into something? (e.g.) if you just entered a command like *read.table(....)* then it will read in the data, but it wont be stored in anything. you have to store it in something, (e.g.) *data <- read.table(.....)*, and then it will be stored in the object 'data'. 3) have you done something like save it in 'data' but then try to call on it using 'Data'? R is case sensitive, so capitals/lower-case make a difference. i hope that helps...
Kishore Kumar (2 years ago)
Great Tutorial. Thanks for providing it..!!
you're welcome +Kishore Kumar !
Christopher Bova (2 years ago)
Hi +Boves Bova , i would recommend to take a look at the data is a spreadsheet application (something like Excel), if you want to view the data as it is. R is better for data analysis and manipulation.
Manjurul Haque (2 years ago)
Thanks a lot for these wonderful tutorial series. I would really appreciate if you upload some tutorials on analyses of big data (metagenomics or transcriptomics or metabolomics).....once again thank you very much for all the tutorials.
Blerina Idrizi (2 years ago)
These have been so helpful! Thanks you
you're welcome +Blerina Idrizi !
Lupupa Musonda (2 years ago)
Brittany M (2 years ago)
When I try to import data I get the following: Data1 <- read.table(file.choose(), header=TRUE) Error in make.names(col.names, unique = TRUE) : invalid multibyte string 74 ...what does this mean?
Mohamed Abukar (2 years ago)
you're welcome +Maxamed Abuukar !
Jan van Dalen (2 years ago)
Hey! so I'm brand new to R, I've installed it and been able to do some stuff... But how do I get my window to be in that format? I only have the console showing. How do I get the two windows on the right showing?
Hansraj Khubchandani (2 years ago)
+Jan van Dalen hey just wondering , how are you doing with learning this language.?? I'm new, so how was the last three months learning R?
Jan van Dalen (2 years ago)
+Jan van Dalen Never mind! RStudio!
Mehemmed Memmedli (3 years ago)
hi could you add scripts also?
bukenyafz4 (3 years ago)
thanks +bukenyafz4 !
Sven Cammerer (3 years ago)
Great stuff! Very easy to follow hacking this into R myself, whilst you speak! And exactly what I need! Cheers, Sven
good to hear +Sven Cammerer !
obinna okechuku (3 years ago)
I love the work you did on these videos. so easy to follow, great job mate!
Thanks +obinna okechuku !
nripcess (3 years ago)
Thanks a bunch! I was struggling to understand these concepts.
infinity8636 (3 years ago)
Hi Mike, I have viewed _so_many_ videos on R. These are the simplest and the best. Precise and perfect! Thanks a lot!
Janos Leier (3 years ago)
thumbs up! Thanks for your tutorials!
thanks +Janos Leier !
fanobennemsi (3 years ago)
Hi....how do you access .rda file located in the 'data' folder (made with save(vector,"MyData.rda") ) ? I thought the point of these files is that I can load them without having to specify a path - for example when it is part of a package. I tried the data("MyData") but it wouldn't load the data. How are these .rda file used in a function?
good to hear you've got it all sorted out +fanobennemsi
fanobennemsi (3 years ago)
Hi....I think I finally found a way to do just that: First I save the vector with: save(lookuptable,file = "C:/tmp/lookuptable.rda") and copy the resulting .rda file into the R-data directory. Then I can get it back without path, this way: data("lookuptable")     lookuptable <- get("lookuptable", pos=globalenv()) It seems to matter that the name of the file is the same (including upper/lower caps) as the vector I read this into. Took a long time to find this.
fanobennemsi (3 years ago)
Thanks, however, when I need this data for one of the functions in the package (behind the scene - like resource data in a C# method), how do I load it without the user of my package being bothered with specifying paths or anything at all. What I have is a lookup table that one of my functions needs. I thought this is what .rda files can be used for in the data folder. But I am not able to read it in - at least not without specifying MY environment specific path. How do other people accomplish that I wonder. Thanks again for any hint. Much appreciated! Norman
Hi +fanobennemsi , you can usually load those using the load command: *load("MyData.RDA")* . you shouldn't need to specify the path to the file, as long as the file is saved in your current working directory. by default, it will be saved in the current working directory, but if you move the file to a new location, or if you change your working directory, then you will have to specify the path to the file.
Christiana J. (3 years ago)
you're welcome +Christiana J. , we're glad you're finding them useful!
Guddu Sharma (3 years ago)
very good explanation
Thanks +Guddu Sharma !
Anvika Kumar (3 years ago)
Heyyy I tried to upload a csv file in R but it shows an error "Error in scan". How to i tackle this. Thanks.
Anvika Kumar (3 years ago)
Okay thank you so much
if you want to use the variables by name you have to first *attach* the data (e.g.) *attach(data_name)*.  if you don't attach, then you have to use the \$ to extract the variables (e.g.) *class(data_name\$variable_name)* i explain all of these in my series of videos.  id recommend to watch the series of videos, in order, as they will address most of the questions you have or will have.
Anvika Kumar (3 years ago)
If you have a email id can I attach a screenshot and show you.
Anvika Kumar (3 years ago)
I figured this out. But now I am having a problem in reading the variables. I used names to get the names of variables form my data set but when i am trying to use them like class( variable name) it is not reading the variables.
+Anvika Kumar i have a video showing how to do exactly this, so i will direct you to that. you can watch the video here: https://www.youtube.com/watch?v=qPk0YEKhqB8
Yashwant Sinha (3 years ago)
Thanks for the tutorials ! they are very informative and helped me understand R and its capabilities.
Doreen Lim (3 years ago)
Thank you, it is clear and simple to understand :)
Vinay Thakur (3 years ago)
Thanks for simple tutorials! Do you have tutorials over Statistics also? I'm learning it for analytics.
Elifuraha Elisha (1 year ago)
Vinay Thakur I like your tutorials,easy to follow
JholWol (3 years ago)
Thanks a lot for these tutorials!!! They are so useful and easy to follow!!!
thanks +funnBuzzz !
Taksh Sharma (3 years ago)
Thanks for simple tutorials! Do you have tutorials over Statistics also? I'm learning it for analytics.
Taksh Sharma (3 years ago)
+MarinStatsLectures That sounds great. I hope to get to view more of such nice tutorials.
Thanks +Taksh Sharma ! not yet, we plan to create a series teaching intro/intermediate level stats, but we haven't had the time to really get started on that yet.
Thanks a lot for these tutorials!!! They are so useful and easy to follow!!!
you're welcome +Maria Cecilia Santos Popper !
siba narayana Sahu (3 years ago)
very nice learning exp.how to import a excel file  sir.
thanks +siba narayana Sahu
Megh Poudel (3 years ago)
Great Tutorial, I was really impressed with the clarity and quality of the video. I learned more here than I learned in class.
Rajendra Dulal (3 years ago)
Excellent videos!  Very helpful for beginners . Can I request you to post DEA i.e. data envelopment analysis with r video?
thanks +dulalR Nepal. sorry, but i don't know DEA well enough to create a high quality tutorial for it.
Jeff L (3 years ago)
Hi Mike. Hope you are doing well. I am trying to do some cost-effectiveness analysis for my PhD project. Can you suggest some R packages for cost-effectiveness analysis? I am also interested in meta-analysis with R. Thank you.
Jeff L (3 years ago)
Thanks, Mike..
+Yiqun Lin thanks, things are good, hope you're doing well, and progressing with your work! those aren't areas of specialty for me, so i can only recommend things second hand, but not based on my own personal experience with them. for cost-effectiveness, id say to check out "BCEA" or "ICEinfer" , and for meta analysis, there are tons of packages that do different things...check out this link, as it explains a bunch of different packages, and what meta-analysis tools they have: http://cran.r-project.org/web/views/MetaAnalysis.html
Ravi Mandal (3 years ago)
Thank you for short and clear notes on r. From India.
+Sitworld Solutions you're welcome
Ramanan R. V. (3 years ago)
Thank you, +MarinStatsLectures. That was helpful, especially the file.choose option. It takes away the pain of remembering the file path. Does if work if I use R console instead of RStudio?
Hi +Ramanan R. V. , yes, all commands will be the same using just the R console.  the only difference with RStudio is that it takes the console, the plot window, etc, and organizes them a bit more neatly.
heroinhero69 (3 years ago)
Hey great videos, really like your straightforward approach! Any chance you might also make a series on STATA?
+heroinhero69 sorry, I'm not familiar with any STATA tutorials online that i would recommend.
heroinhero69 (3 years ago)
+MarinStatsLectures That's unfortunate. Not that you would know, but do you have any video tutorials here on youtube on that you might want to recommend?
Thanks +heroinhero69 !  we don't have any plans to create STATA videos at the moment.
Izabela Edmunds (3 years ago)
I wanted to know if there is a limit to the number of rows that can be read?
Hi +Izabela Edmunds , i'm sure there must be some limit, but i don't know what it is.  R can handle pretty large datasets, but how large i couldn't say.
LOCK 13 (3 years ago)
Hello Sir, The videos are hugely helpful. But i am having problem opening a file directly from folder as shown in the video  "data1 = read.table(file="C:\user\Dominator\Desktop\ratTAB.txt", header=T, sep="\t")" and i am getting an error as Error: '\u' used without hex digits in character string starting ""C:\u" Not sure what's wrong, can you help please. Thank you
Hi +Srijan Ghosh , it's always hard to troubleshoot these things from a distance, but my guess is that you're working in Windows, and you will need to include a double-slash after the C, (e.g.) C:\\user\Dominator\...  Or, i know for my mac, it uses forward slashes, not back-slash.  what i think is easiest is to go to the file you want to import and look at the "properties" of it, and somewhere there it should give you the location of the file, and you can see how to specify the path to the file from there...  hope that helps you sort it out