Skip to content

Commit

Permalink
fix datas
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-paul-2006 committed Feb 1, 2024
1 parent d827b62 commit 5e5e69d
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions introToR/inst/extdata/presRaw/introToR_Session1.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ kable(minRepdf[,1:4], format='html')
Tables from text files can be read with **read.table()** function

```{r,echo=T}
Table <- read.table("../data/readThisTable.csv",sep=",",header=T)
Table <- read.table("data/readThisTable.csv",sep=",",header=T)
Table[1:4,1:3]
```

Expand All @@ -1658,7 +1658,7 @@ read.table() allows for significant control over reading files through its many
The **row.names** argument can be used to specify a column to use as row names for the resulting data frame. Here we use the first column as row names.

```{r,echo=T}
Table <- read.table("../data/readThisTable.csv",sep=",",header=T,row.names=1)
Table <- read.table("data/readThisTable.csv",sep=",",header=T,row.names=1)
Table[1:4,1:3]
```

Expand All @@ -1670,7 +1670,7 @@ As mentioned, data which is read into R through read.table() will be of data fra
Similar to when we create data frames, we can control whether the data is read in as a factor or not with the **stringsAsFactors** argument. The default of this has also changed in R 4.0, from **TRUE** to **FALSE**.

```{r,echo=T}
Table <- read.table("../data/readThisTable.csv", sep=",", header=T, stringsAsFactors=F)
Table <- read.table("data/readThisTable.csv", sep=",", header=T, stringsAsFactors=F)
```

Other very useful functions for read table include:
Expand Down Expand Up @@ -1702,7 +1702,7 @@ The **scan()** function allows for the selection of particular columns to be rea


```{r,echo=T}
x <- scan("../data/readThisTable.csv",sep=",",
x <- scan("data/readThisTable.csv",sep=",",
what = c("character",rep("numeric", 6)),skip=1)
x[1:3]
```
Expand All @@ -1715,13 +1715,13 @@ Once we have our data analysed in R, we will want to export it to a file.
The most common method is to use the write.table() function

```{r,echo=T}
write.table(Table, file="../data/writeThisTable.csv", sep=",")
write.table(Table, file="data/writeThisTable.csv", sep=",")
```

Since our data has column names but no row names, I will provide the arguments col.names and row.names to write.table()

```{r,echo=T}
write.table(Table, file="../data/writeThisTable.csv", sep=",", row.names =F, col.names=T)
write.table(Table, file="data/writeThisTable.csv", sep=",", row.names =F, col.names=T)
```

---
Expand Down Expand Up @@ -1788,7 +1788,7 @@ We can use the **import()** function to read in our csv file. We simple specify
**import(_Filename_)**

```{r,echo=T,eval=TRUE}
Table <- import("../data/readThisTable.csv")
Table <- import("data/readThisTable.csv")
Table[1:2,]
```

Expand All @@ -1800,9 +1800,9 @@ By default we will only retrieve the first sheet.
We can specify the sheet by name or number using the **which** argument.

```{r,echo=T,eval=TRUE}
Table <- import("../data/readThisXLS.xls",
Table <- import("data/readThisXLS.xls",
which=2)
Table <- import("../data/readThisXLS.xls",
Table <- import("data/readThisXLS.xls",
which="Metadata")
Table[1:2,]
```
Expand All @@ -1815,7 +1815,7 @@ If we want to import all sheets, we can use the **import_list**.
This returns a *list* containing our two spreadsheets. The list has two elements named after the corresponding XLS sheet.

```{r,echo=T,eval=TRUE}
Table <- import_list("../data/readThisXLS.xls")
Table <- import_list("data/readThisXLS.xls")
names(Table)
```

Expand All @@ -1837,7 +1837,7 @@ We can export our data back to file using the **export()** function and specifyi

```{r,echo=T,eval=TRUE}
ExpressionScores <- Table$ExpressionScores
export(ExpressionScores,file = "../data/writeThisXLSX.xlsx")
export(ExpressionScores,file = "data/writeThisXLSX.xlsx")
```

Expand All @@ -1848,7 +1848,7 @@ We can export a list of data.frames to Excel's xlsx format using the **export()*

```{r,echo=T,eval=TRUE}
names(Table) <- c("expr","meta")
export(Table,file = "../data/writeThisMultipleXLSX.xlsx")
export(Table,file = "data/writeThisMultipleXLSX.xlsx")
```

Expand Down

0 comments on commit 5e5e69d

Please sign in to comment.