vendredi 7 septembre 2018

pass the content of one data frame to another in r

I am currently learning R in order to write my thesis in my university.

In my project I have one data frame with 2 columns and 6001 rows. In my first column I have numbers from 10000,9999,9998 until 4000 and in the second column I have numeric elements. In my mind I want to do something very simple. I want to create a second data frame with half the size of the original data frame, that contains the even numbers of the first column with the numeric from the second column.

I tried some scripts that didn't go as planned. My first script was:ifelse(tkk[1] %% 2 == 0, tkal<-tkk, 0). And then I tried this one: tkal <-case_when((tkk[1]%%2 ==0)~ tkk). But both of my scripts didn't run or have not the results that I wanted.

Does any of you have a solution or a better idea so I could solve this simple task?

Thank you in advance

Aucun commentaire:

Enregistrer un commentaire