Split dataframe when value in first column is not NA -


i have imported data set looking excel r-studio

station indicator resp status    1        ca      +      16     1        zn      -      134    1        pb      +      3.5    2        ca      +      4.6    3        zn      -      156 

==========

i split dataframe in way, when "station" not na make new dataframe name of station fx "1". in way have dataframe each of stations.

station 1:   ca      +      16    zn      -      134   pb      +      3.5  station 2:   ca      +      4.6  station 3:    zn      -      156 

i have tried split function

df1=split(df,station=!"na"]) 

but not work me

we split dataset ('df1') first column i.e. station

 lst <- split(df1[-1], df1$station)  names(lst) <- paste0('station', names(lst)) 

if need separate objects in global environment (not reccommended)

 list2env(lst, envir = .globalenv)   station1  #   indicator resp status  #1        ca    +   16.0  #2        zn    -  134.0  #3        pb    +    3.5 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -