r - How to create a table from a .csv file? -


i have following data .csv file:

sp  country   rmu           temp    males   females  cc  australia pacific, s    25.00   0   7        cc  australia pacific, s    26.00   17  1    ei  stp       atlantic, e   28.00   21  2        ei  brazil    atlantic, w   27.50   8   1 nd  australia pacific, s    28.00   2   0    

and want create new table males values, "sp==cc", meaning

males 0 17 

i have tried this:

m=subset(file3_tmf, sp=="cc")$males 

but creating "integer (empty)".

can help?

those "," in rmu field create mess ... using data, assuming .csv on top of have "," in between "pacific , s":

1) scan file (read csv file)
2) unlist (outcome of scan list)
3) transform unlisted in matrix 8 columns (due "," ahead of s/e/w)

> dat <- matrix(unlist(scan(file = "dat.csv", = list(rep("character",8)),                 sep = ",", skip = 1)), ncol = 8, byrow = true) 

4) subset rows 1 column == "cc", show column 7 ("male")

> dat[dat[,1] == "cc",7] 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -