I am a beginner in R and I have been working on a data that has 2075260 rows and ten columns. The file has a .txt extension. While reading the dataset by read.csv or read.table and running str on the data frame I get this message.

data <- read.csv("mydata.txt") str(data) 'data.frame': 2075260 obs. of 1 variable: $ V1: Factor w/ 2075260 levels "1/1/2007;00:00:00;2.580;0.136;241.970;10.600;0.000;0.000;0.000",..: 2075260 491041 491042 491043 491044 491045 491046 491047 491048 491049 ... 

I want store this data in a dataframe that has 2075260 obs and ten variables but there appears to be a problem that I am not able to figure out. I searched similar questions asked but could'nt find the answer. Your answer will be very much appreciated!

Regards,

6

1 Answer

You should use read.table for a .txt file, read.csv should be used for .csv files instead. However use read.table:

data <- read.table("mydata.txt",sep=" ",header=T) 

With sep you specify the "character" that appears between 2 columns, for e.g ',' or space (" ") or a tab ("\t"). Also with header you specify if in your data is present a line that contains the names for each columns (it's the first line).

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.