Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

I just wanted to eliminate the value that is this "T00:00:00" from the time columns from each of the 3 layers of my data frame in R. I dont know how to eliminate the a record from the data. My data looks like the following:

[[1]]

# A tibble: 1 x 3

  observation HRpcode timeseries

        <int> <chr>   <chr>  

1           1 NA      NA    

[[2]]

# A tibble: 74 x 3

   observation time                ` NDVI`

         <int> <chr>               <chr>

 1           1 2014-01-01T00:00:00 0.3793765496776215 

 2           2 2014-02-01T00:00:00 0.21686891782421552

 3           3 2014-03-01T00:00:00 0.3785652933528299 

# ... with 64 more rows

[[3]]

# A tibble: 74 x 3

   observation time                ` NDVI`    

         <int> <chr>               <chr>    

 1           1 2014-01-01T00:00:00 0.4071076986818826

 2           2 2014-02-01T00:00:00 0.09090719657570319

 3           3 2014-03-01T00:00:00 0.35214166081795284

# ... with 64 more rows

[[4]]

# A tibble: 74 x 3

   observation time                ` NDVI` 

         <int> <chr>               <chr>     

 1           1 2014-01-01T00:00:00 0.3412131556625801 

 2           2 2014-02-01T00:00:00 0.18815996897460135

 3           3 2014-03-01T00:00:00 0.5218904976415136 

# ... with 64 more rows

How do I isolate and manipulate the columns? 

1 Answer

0 votes
by (107k points)

What you can do is with the help of lapply function you can loop the lists and can easily eliminate the text after T.

Let us say the list is called list_df, the rest of the code is as follows:

list_df <- lapply(list_df, function(x) {x$time <- sub('T.*', '', x$time);x})

If you are a beginner and want to know more about R Programming then do check out the following R programming tutorial that will help you in learning R from scratch. 

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...