To import TSV file in R, you can use read_table() or read_tsv() function from readr package.
The following methods show how you can do it with syntax.
Method 1: Use read_table() Function
library(readr)
read.table("path of file")
Method 2: Use read_tsv() Function
library(readr)
read_tsv('path of file')
The following examples show how to import TSV file in R using different function.
Use read_table() Function
Let’s see how we can use read_table() function from readr package in R:
# Import TSV file into data frame
df <- read_table('sample.tsv')
# Print data frame
print(df)
Output:
Date Machine_type Status Pressure Temperature
<chr> <chr> <lgl> <dbl> <dbl>
1 21-10-2023 Mach_1 TRUE 11 45.6
2 22-10-2023 Mach_2 TRUE 12 47.2
3 23-10-2023 Mach_3 FALSE 10 46.1
4 24-10-2023 Mach_4 TRUE 11 46.8
Here the output shows imported data from sample.tsv file.
Use read_tsv() Function
Let’s see how we can use read_tsv() function from readr package in R:
# Import library
library(readr)
# Import TSV file into data frame
df <- read_tsv('sample.tsv')
# Print data frame
print(df)
Output:
Date Machine_type Status Pressure Temperature
<chr> <chr> <lgl> <dbl> <dbl>
1 21-10-2023 Mach_1 TRUE 11 45.6
2 22-10-2023 Mach_2 TRUE 12 47.2
3 23-10-2023 Mach_3 FALSE 10 46.1
4 24-10-2023 Mach_4 TRUE 11 46.8
Here the output shows data from sample.tsv file which imported using read_tsv() function.