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: