Import, read and convert cross data to a data frame.

Asked

Viewed 415 times

2

I have a table that is not in the standard reading format of R, that is, it has a variable in column (time) and two in line with the data arranged side by side (subject and treatment). Someone could shed some light on how to get R to import, read and convert this data that is crossed into a data frame?

Concentrações plasmáticas individuais

  • Weidson, please post a sample of your data as file, selectable text or R object, because this way we cannot read your data without creating it manually.

  • About the problem itself, I would solve in excel. Just create a new line and use the function CONCATENAR in rows 2 and 3 to create the column name, and after that you can delete the first three rows or use the argument skip.

  • Guys, thank you so much for your help and please excuse the lack of experience with R and the forum (little by little I’ll learn more). When I posted this question I did not know if you want the basic premises of reading R. I mean, I had to become more familiar with the language to find the solution with the help of a colleague of this forum. In order to make R understand the connection between data and variables we cannot have merged as illustrated above (in this way it is practically impossible to form variables).

  • Over time I discovered the basic premises that to make the manipulation it is necessary to always have variables arranged in columns. So what I needed to know was simply how to form variables. It follows the link of what I actually intended to do.link

2 answers

1

Reading is no problem, you can use read.table with Skip =2 parameter, to skip the first 2 lines, and read the data from a csv file. Then you can use reshape reshape2 to put bank in long format.

  • Okay...I got the hint. But how could I automate the name change? Would I have 500 subjects to manually change the name? It would be possible to automate the name change?

  • Okay...I got the hint. But how could I get the treatment information? Please note what time the subject takes treatment A in the first period and B in the second and time he takes treatment B in the first period and A in the second. I need to index this information in the data frame.

1

Dear @Weidsonc.Peel, could you improve your questions? Put a larger piece of the spreadsheet and explain better what you want! Regarding reading the database and importing to the R you can use the code:

library(readr)
df <- read_delim("local_do_arquivo",";", escape_double = FALSE, trim_ws = TRUE,skip = 2)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.