[R] Split Dataframe into several

Rasmus Liland jr@| @end|ng |rom po@teo@no
Mon Mar 8 14:17:32 CET 2021


Dear Javad,

	data <- "Date Cases Country
	2020-12-14 746 Country1
	2020-12-15 324 Country1
	2020-12-15   1 Country3
	2020-12-13 298 Country2"
	data <- read.table(text=data, header=T)
	x <- reshape(
	  data=data,
	  timevar = "Country",
	  idvar = "Date",
	  direction = "wide")
	data
	x

yields

	        Date Cases  Country
	1 2020-12-14   746 Country1
	2 2020-12-15   324 Country1
	3 2020-12-15     1 Country3
	4 2020-12-13   298 Country2
	        Date Cases.Country1
	1 2020-12-14            746
	2 2020-12-15            324
	4 2020-12-13             NA
	  Cases.Country3 Cases.Country2
	1             NA             NA
	2              1             NA
	4             NA            298

Best,
Rasmus

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20210308/3b88debe/attachment.sig>


More information about the R-help mailing list