[英]Extracting decimal values from a data frame in R
I have a GBIF data frame of the species distribution.我有一个物种分布的 GBIF 数据框。 Some of the occurrences are not in the long and lat columns.
某些事件不在 long 和 lat 列中。 How can I extract the decimal values for each row (each species sample)?
如何提取每一行(每个物种样本)的十进制值? "$"
“$”
Assuming that you want to extract the decimal values of lat / long coordinates in decimal format, you could use something like this:假设你想以十进制格式提取纬度/经度坐标的十进制值,你可以使用这样的东西:
#Some sample data
df<-data.frame (Sp = paste0("Sp",seq(1,10,1)),
lat = seq(1,9,0.88),
long = seq (1,17,1.66))
#Get the values before (lat1 and long1) and after (lat2 and long2) the decimal point
df$lat1 <- floor(df$lat)
df$lat2 <- df$lat %% floor(df$lat)
df$long1 <- floor(df$long)
df$long2 <- df$long %% floor(df$long)
#The result looks like this:
# Sp lat long lat1 lat2 long1 long2
#1 Sp1 1.00 1.00 1 0.00 1 0.00
#2 Sp2 1.88 2.66 1 0.88 2 0.66
#3 Sp3 2.76 4.32 2 0.76 4 0.32
#4 Sp4 3.64 5.98 3 0.64 5 0.98
#5 Sp5 4.52 7.64 4 0.52 7 0.64
#6 Sp6 5.40 9.30 5 0.40 9 0.30
#7 Sp7 6.28 10.96 6 0.28 10 0.96
#8 Sp8 7.16 12.62 7 0.16 12 0.62
#9 Sp9 8.04 14.28 8 0.04 14 0.28
#10 Sp10 8.92 15.94 8 0.92 15 0.94
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.