Why I got only one column by read.table?

When I read a dataset (25 obs, 4 variables) using syntax below, I just get a one-column variable(394 obs, 1 variables).

What's going wrong?

hospital<-read.table("C:/Users/Lenovo/Desktop/HOSPITAL.DAT.rdata")

What happens if you try:

hospital <- get(load('C:/Users/Lenovo/Desktop/HOSPITAL.DAT.rdata'))

I tried following code in Rstudio, and got NULL.

> hospital <- get(load('C:/Users/Lenovo/Desktop/HOSPITAL.DAT.rdata'))
> hospital
NULL

But if I tried this one, I got what I want.

load('C:/Users/Lenovo/Desktop/HOSPITAL.DAT.rdata')

then hospital consists of 25 obs, 9 variables.

So why read.table() goes wrong here?

hospital<-read.table("C:/Users/Lenovo/Desktop/HOSPITAL.DAT.rdata")

then hospital consists of 394 obs, 1 variable.

Yeah, if I try load() directly, it is correct.

load('C:/Users/Lenovo/Desktop/HOSPITAL.DAT.rdata')

then hospital consists of 25 obs, 9 variables.

So why read.table() goes wrong here? The file type is R Workspace (.rdata).

hospital<-read.table("C:/Users/Lenovo/Desktop/HOSPITAL.DAT.rdata")

then hospital consists of 394 obs, 1 variable.

read.table is for text files.
load is for RData files.

1 Like

get it! Thanks for your patience :slight_smile:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.