How to calculate an easy division extracted from variables of two different textfiles

Hey there!

I am a super beginner, hopefully you can help me!

I want to calculate an easy division of two variables, that I get from two different textfiles. The topic is about sleep research, more specific REM-Density.

So, I have two fodlers with around 60 textfiles. From one folder I need to extract the variable duration (e.g. 0.893)

Name: ,
Date of Recording: 7/26/2017 11:00:00 PM
Recording Code: RES007_BN

Segment Information:

Start Date & Time End time Duration Duration (s)


1 7/26/2017 11:00:00 PM 10:01:00 AM 0 11:01:00 39660.0

REMs/REMs (14 events)

Segment Epoch Start Time (s) Duration (s) Interval (s) Event


1, 1, 863, 17254.065, 0.893, 679.014, REMs
2, 1, 897, 17933.079, 1.842, 7116.967, REMs
3, 1, 1253, 25050.047, 0.930, 7.981, REMs
4, 1, 1253, 25058.028, 0.893, 2.028, REMs
5, 1, 1254, 25060.056, 0.856, 4673.023, REMs
6, 1, 1487, 29733.079, 0.819, 52.074, REMs
7, 1, 1490, 29785.153, 0.800, 230.884, REMs
8, 1, 1501, 30016.037, 0.930, 479.126, REMs
9, 1, 1525, 30495.163, 0.800, 1.935, REMs
10, 1, 1525, 30497.098, 0.837, 47.107, REMs
11, 1, 1528, 30544.205, 0.744, 33.898, REMs
12, 1, 1529, 30578.102, 0.837, 56.074, REMs
13, 1, 1532, 30634.177, 5.749, 72.893, REMs
14, 1, 1536, 30707.070, 1.898, -, REMs

For this first textfile I used the subset function to extract the target variable, skiped the 13 first lines and rounded the variable, summed it up and saved it in a data.frame. I did that separately for each proband. In the end I bind it all together in one csv.file.

For the second textfile, that I need to count from one variable "all the number 5" which means REM stage sleep. But the length of those text files is unequal. How can I do it here? Do you have an idea?

And could I do something like a loop?

Thanks for your help!

Best, Chantal

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.